Compare commits

..

No commits in common. "429c0a53a21438f061555d22e00f2b9ac489d59f" and "bf3c8aa7c7396238ae01a43ed6619c83b506e093" have entirely different histories.

4 changed files with 42 additions and 71 deletions

View file

@ -68,8 +68,8 @@ class _DialogRangePickerState<T extends PhotographyValue> extends State<DialogRa
divisions: widget.values.length - 1,
onChanged: (value) {
setState(() {
_start = value.start.round();
_end = value.end.round();
_start = value.start.toInt();
_end = value.end.toInt();
});
},
),

View file

@ -143,13 +143,10 @@ class EquipmentProfileContainerState extends State<EquipmentProfileContainer>
widget.onExpand();
_controller.forward();
SchedulerBinding.instance.addPostFrameCallback((_) {
Future.delayed(_controller.duration!).then((_) {
Scrollable.ensureVisible(
context,
alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd,
duration: _controller.duration!,
);
});
Scrollable.ensureVisible(
context,
alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd,
);
});
}

View file

@ -17,13 +17,17 @@ class EquipmentProfilesScreen extends StatefulWidget {
}
class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
final Map<String, GlobalKey<EquipmentProfileContainerState>> keysMap = {};
int get profilesCount => keysMap.length;
static const maxProfiles = 5 + 1; // replace with a constant from iap
late List<GlobalKey<EquipmentProfileContainerState>> profileContainersKeys = [];
int get profilesCount => EquipmentProfiles.of(context).length;
@override
void didChangeDependencies() {
super.didChangeDependencies();
_updateProfilesKeys();
profileContainersKeys = EquipmentProfiles.of(context)
.map((e) => GlobalKey<EquipmentProfileContainerState>(debugLabel: e.id))
.toList();
}
@override
@ -31,10 +35,11 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
return SliverScreen(
title: S.of(context).equipmentProfiles,
appBarActions: [
IconButton(
onPressed: _addProfile,
icon: const Icon(Icons.add),
),
if (profilesCount < maxProfiles)
IconButton(
onPressed: _addProfile,
icon: const Icon(Icons.add),
),
IconButton(
onPressed: Navigator.of(context).pop,
icon: const Icon(Icons.close),
@ -50,30 +55,24 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
: [
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index == 0) {
// skip default profile
return const SizedBox.shrink();
}
final profile = EquipmentProfiles.of(context)[index];
return Padding(
padding: EdgeInsets.fromLTRB(
Dimens.paddingM,
index == 0 ? Dimens.paddingM : 0,
Dimens.paddingM,
Dimens.paddingM,
),
child: EquipmentProfileContainer(
key: keysMap[profile.id],
data: profile,
onExpand: () => _keepExpandedAt(index),
onUpdate: _updateProfileAt,
onDelete: () => _removeProfileAt(profile),
),
);
},
childCount: EquipmentProfiles.of(context).length,
(context, index) => index > 0 // skip default
? Padding(
padding: EdgeInsets.fromLTRB(
Dimens.paddingM,
index == 0 ? Dimens.paddingM : 0,
Dimens.paddingM,
Dimens.paddingM,
),
child: EquipmentProfileContainer(
key: profileContainersKeys[index],
data: EquipmentProfiles.of(context)[index],
onExpand: () => _keepExpandedAt(index),
onUpdate: (profileData) => _updateProfileAt(profileData, index),
onDelete: () => _removeProfileAt(index),
),
)
: const SizedBox.shrink(),
childCount: profilesCount,
),
),
SliverToBoxAdapter(child: SizedBox(height: MediaQuery.paddingOf(context).bottom)),
@ -92,47 +91,22 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
});
}
void _updateProfileAt(EquipmentProfile data) {
void _updateProfileAt(EquipmentProfile data, int index) {
EquipmentProfileProvider.of(context).updateProdile(data);
}
void _removeProfileAt(EquipmentProfile data) {
EquipmentProfileProvider.of(context).deleteProfile(data);
void _removeProfileAt(int index) {
EquipmentProfileProvider.of(context).deleteProfile(EquipmentProfiles.of(context)[index]);
}
void _keepExpandedAt(int index) {
keysMap.values.toList().getRange(0, index).forEach((element) {
profileContainersKeys.getRange(0, index).forEach((element) {
element.currentState?.collapse();
});
keysMap.values.toList().getRange(index + 1, profilesCount).forEach((element) {
profileContainersKeys.getRange(index + 1, profilesCount).forEach((element) {
element.currentState?.collapse();
});
}
void _updateProfilesKeys() {
final profiles = EquipmentProfiles.of(context);
if (profiles.length > keysMap.length) {
// profile added
final List<String> idsToAdd = [];
for (final profile in profiles) {
if (!keysMap.keys.contains(profile.id)) idsToAdd.add(profile.id);
}
for (final id in idsToAdd) {
keysMap[id] = GlobalKey<EquipmentProfileContainerState>(debugLabel: id);
}
idsToAdd.clear();
} else if (profiles.length < keysMap.length) {
// profile deleted
final List<String> idsToDelete = [];
for (final id in keysMap.keys) {
if (!profiles.any((p) => p.id == id)) idsToDelete.add(id);
}
idsToDelete.forEach(keysMap.remove);
idsToDelete.clear();
} else {
// profile updated, no need to updated keys
}
}
}
class _EquipmentProfilesListPlaceholder extends StatelessWidget {

View file

@ -1,7 +1,7 @@
name: lightmeter
description: Lightmeter app inspired by Material 3 design system.
publish_to: "none"
version: 0.14.0+39
version: 0.13.2+38
environment:
sdk: ">=3.0.0 <4.0.0"