fix choose rulset & choose group view not saving

This commit is contained in:
2026-01-03 11:02:38 +01:00
parent e4ae526d93
commit 16e1f542f5
2 changed files with 101 additions and 69 deletions

View File

@@ -57,61 +57,78 @@ class _ChooseGroupViewState extends State<ChooseGroupView> {
), ),
centerTitle: true, centerTitle: true,
), ),
body: Column( body: PopScope(
children: [ // This fixes that the Android Back Gesture didn't return the
Padding( // selectedGroupId and therefore the selected Group wasn't saved
padding: const EdgeInsets.symmetric(horizontal: 10), canPop: false,
child: CustomSearchBar( onPopInvokedWithResult: (bool didPop, Object? result) {
controller: controller, if (didPop) {
hintText: hintText, return;
onChanged: (value) { }
setState(() { Navigator.of(context).pop(
filterGroups(value); selectedGroupId == ''
}); ? null
}, : widget.groups.firstWhere(
), (group) => group.id == selectedGroupId,
), ),
Expanded( );
child: Visibility( },
visible: filteredGroups.isNotEmpty, child: Column(
replacement: Visibility( children: [
visible: widget.groups.isNotEmpty, Padding(
replacement: const TopCenteredMessage( padding: const EdgeInsets.symmetric(horizontal: 10),
icon: Icons.info, child: CustomSearchBar(
title: 'Info', controller: controller,
message: 'You have no groups created yet', hintText: hintText,
), onChanged: (value) {
child: const TopCenteredMessage( setState(() {
icon: Icons.info, filterGroups(value);
title: 'Info', });
message: 'There is no group matching your search',
),
),
child: ListView.builder(
padding: const EdgeInsets.only(bottom: 85),
itemCount: filteredGroups.length,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
setState(() {
if (selectedGroupId != filteredGroups[index].id) {
selectedGroupId = filteredGroups[index].id;
} else {
selectedGroupId = '';
}
});
},
child: GroupTile(
group: filteredGroups[index],
isHighlighted:
selectedGroupId == filteredGroups[index].id,
),
);
}, },
), ),
), ),
), Expanded(
], child: Visibility(
visible: filteredGroups.isNotEmpty,
replacement: Visibility(
visible: widget.groups.isNotEmpty,
replacement: const TopCenteredMessage(
icon: Icons.info,
title: 'Info',
message: 'You have no groups created yet',
),
child: const TopCenteredMessage(
icon: Icons.info,
title: 'Info',
message: 'There is no group matching your search',
),
),
child: ListView.builder(
padding: const EdgeInsets.only(bottom: 85),
itemCount: filteredGroups.length,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
setState(() {
if (selectedGroupId != filteredGroups[index].id) {
selectedGroupId = filteredGroups[index].id;
} else {
selectedGroupId = '';
}
});
},
child: GroupTile(
group: filteredGroups[index],
isHighlighted:
selectedGroupId == filteredGroups[index].id,
),
);
},
),
),
),
],
),
), ),
); );
} }

View File

@@ -52,25 +52,40 @@ class _ChooseRulesetViewState extends State<ChooseRulesetView> {
), ),
centerTitle: true, centerTitle: true,
), ),
body: ListView.builder( body: PopScope(
padding: const EdgeInsets.only(bottom: 85), // This fixes that the Android Back Gesture didn't return the
itemCount: widget.rulesets.length, // selectedRulesetIndex and therefore the selected Ruleset wasn't saved
itemBuilder: (BuildContext context, int index) { canPop: false,
return TitleDescriptionListTile( onPopInvokedWithResult: (bool didPop, Object? result) {
onPressed: () async { if (didPop) {
setState(() { return;
if (selectedRulesetIndex == index) { }
selectedRulesetIndex = -1; Navigator.of(context).pop(
} else { selectedRulesetIndex == -1
selectedRulesetIndex = index; ? null
} : widget.rulesets[selectedRulesetIndex].$1,
});
},
title: translateRulesetToString(widget.rulesets[index].$1),
description: widget.rulesets[index].$2,
isHighlighted: selectedRulesetIndex == index,
); );
}, },
child: ListView.builder(
padding: const EdgeInsets.only(bottom: 85),
itemCount: widget.rulesets.length,
itemBuilder: (BuildContext context, int index) {
return TitleDescriptionListTile(
onPressed: () async {
setState(() {
if (selectedRulesetIndex == index) {
selectedRulesetIndex = -1;
} else {
selectedRulesetIndex = index;
}
});
},
title: translateRulesetToString(widget.rulesets[index].$1),
description: widget.rulesets[index].$2,
isHighlighted: selectedRulesetIndex == index,
);
},
),
), ),
), ),
); );