Compare commits

...

2 commits

Author SHA1 Message Date
github-actions[bot]
429c0a53a2 Version bump 2023-09-02 21:13:17 +00:00
Vadim
f39177919c
Equipment profiles issues (#112)
* Fixed equipment profiles sections collapsing

* Fixed range picker dialog

* Refined equipment profiles sections handling
2023-09-02 22:29:35 +02:00
4 changed files with 71 additions and 42 deletions

View file

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

View file

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

View file

@ -17,17 +17,13 @@ class EquipmentProfilesScreen extends StatefulWidget {
} }
class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> { class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
static const maxProfiles = 5 + 1; // replace with a constant from iap final Map<String, GlobalKey<EquipmentProfileContainerState>> keysMap = {};
int get profilesCount => keysMap.length;
late List<GlobalKey<EquipmentProfileContainerState>> profileContainersKeys = [];
int get profilesCount => EquipmentProfiles.of(context).length;
@override @override
void didChangeDependencies() { void didChangeDependencies() {
super.didChangeDependencies(); super.didChangeDependencies();
profileContainersKeys = EquipmentProfiles.of(context) _updateProfilesKeys();
.map((e) => GlobalKey<EquipmentProfileContainerState>(debugLabel: e.id))
.toList();
} }
@override @override
@ -35,7 +31,6 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
return SliverScreen( return SliverScreen(
title: S.of(context).equipmentProfiles, title: S.of(context).equipmentProfiles,
appBarActions: [ appBarActions: [
if (profilesCount < maxProfiles)
IconButton( IconButton(
onPressed: _addProfile, onPressed: _addProfile,
icon: const Icon(Icons.add), icon: const Icon(Icons.add),
@ -55,8 +50,14 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
: [ : [
SliverList( SliverList(
delegate: SliverChildBuilderDelegate( delegate: SliverChildBuilderDelegate(
(context, index) => index > 0 // skip default (context, index) {
? Padding( if (index == 0) {
// skip default profile
return const SizedBox.shrink();
}
final profile = EquipmentProfiles.of(context)[index];
return Padding(
padding: EdgeInsets.fromLTRB( padding: EdgeInsets.fromLTRB(
Dimens.paddingM, Dimens.paddingM,
index == 0 ? Dimens.paddingM : 0, index == 0 ? Dimens.paddingM : 0,
@ -64,15 +65,15 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
Dimens.paddingM, Dimens.paddingM,
), ),
child: EquipmentProfileContainer( child: EquipmentProfileContainer(
key: profileContainersKeys[index], key: keysMap[profile.id],
data: EquipmentProfiles.of(context)[index], data: profile,
onExpand: () => _keepExpandedAt(index), onExpand: () => _keepExpandedAt(index),
onUpdate: (profileData) => _updateProfileAt(profileData, index), onUpdate: _updateProfileAt,
onDelete: () => _removeProfileAt(index), onDelete: () => _removeProfileAt(profile),
), ),
) );
: const SizedBox.shrink(), },
childCount: profilesCount, childCount: EquipmentProfiles.of(context).length,
), ),
), ),
SliverToBoxAdapter(child: SizedBox(height: MediaQuery.paddingOf(context).bottom)), SliverToBoxAdapter(child: SizedBox(height: MediaQuery.paddingOf(context).bottom)),
@ -91,22 +92,47 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
}); });
} }
void _updateProfileAt(EquipmentProfile data, int index) { void _updateProfileAt(EquipmentProfile data) {
EquipmentProfileProvider.of(context).updateProdile(data); EquipmentProfileProvider.of(context).updateProdile(data);
} }
void _removeProfileAt(int index) { void _removeProfileAt(EquipmentProfile data) {
EquipmentProfileProvider.of(context).deleteProfile(EquipmentProfiles.of(context)[index]); EquipmentProfileProvider.of(context).deleteProfile(data);
} }
void _keepExpandedAt(int index) { void _keepExpandedAt(int index) {
profileContainersKeys.getRange(0, index).forEach((element) { keysMap.values.toList().getRange(0, index).forEach((element) {
element.currentState?.collapse(); element.currentState?.collapse();
}); });
profileContainersKeys.getRange(index + 1, profilesCount).forEach((element) { keysMap.values.toList().getRange(index + 1, profilesCount).forEach((element) {
element.currentState?.collapse(); 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 { class _EquipmentProfilesListPlaceholder extends StatelessWidget {

View file

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