From a976fcdaff50a4f3450c30337cf88f29f457b8bb Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Sat, 2 Sep 2023 20:33:30 +0200 Subject: [PATCH] Fixed equipment profiles sections collapsing --- .../screen_equipment_profile.dart | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart index 0168608..66f2a45 100644 --- a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart +++ b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart @@ -19,15 +19,15 @@ class EquipmentProfilesScreen extends StatefulWidget { class _EquipmentProfilesScreenState extends State { static const maxProfiles = 5 + 1; // replace with a constant from iap - late List> profileContainersKeys = []; - int get profilesCount => EquipmentProfiles.of(context).length; + final Map> keysMap = {}; + int get profilesCount => keysMap.length; @override void didChangeDependencies() { super.didChangeDependencies(); - profileContainersKeys = EquipmentProfiles.of(context) - .map((e) => GlobalKey(debugLabel: e.id)) - .toList(); + EquipmentProfiles.of(context).forEach((profile) { + keysMap[profile.id] ??= GlobalKey(debugLabel: profile.id); + }); } @override @@ -64,7 +64,7 @@ class _EquipmentProfilesScreenState extends State { Dimens.paddingM, ), child: EquipmentProfileContainer( - key: profileContainersKeys[index], + key: keysMap.values.toList()[index], data: EquipmentProfiles.of(context)[index], onExpand: () => _keepExpandedAt(index), onUpdate: (profileData) => _updateProfileAt(profileData, index), @@ -72,7 +72,7 @@ class _EquipmentProfilesScreenState extends State { ), ) : const SizedBox.shrink(), - childCount: profilesCount, + childCount: keysMap.length, ), ), SliverToBoxAdapter(child: SizedBox(height: MediaQuery.paddingOf(context).bottom)), @@ -100,10 +100,10 @@ class _EquipmentProfilesScreenState extends State { } void _keepExpandedAt(int index) { - profileContainersKeys.getRange(0, index).forEach((element) { + keysMap.values.toList().getRange(0, index).forEach((element) { element.currentState?.collapse(); }); - profileContainersKeys.getRange(index + 1, profilesCount).forEach((element) { + keysMap.values.toList().getRange(index + 1, profilesCount).forEach((element) { element.currentState?.collapse(); }); }