Refactoring
This commit is contained in:
@@ -5,12 +5,12 @@ import 'package:game_tracker/presentation/widgets/tiles/group_tile.dart';
|
|||||||
|
|
||||||
class ChooseGroupView extends StatefulWidget {
|
class ChooseGroupView extends StatefulWidget {
|
||||||
final List<Group> groups;
|
final List<Group> groups;
|
||||||
final int? selectedGroupIndex;
|
final int initialGroupIndex;
|
||||||
|
|
||||||
const ChooseGroupView({
|
const ChooseGroupView({
|
||||||
super.key,
|
super.key,
|
||||||
required this.groups,
|
required this.groups,
|
||||||
this.selectedGroupIndex,
|
required this.initialGroupIndex,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -18,11 +18,11 @@ class ChooseGroupView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ChooseGroupViewState extends State<ChooseGroupView> {
|
class _ChooseGroupViewState extends State<ChooseGroupView> {
|
||||||
late int selectedGroup;
|
late int selectedGroupIndex;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
selectedGroup = widget.selectedGroupIndex ?? -1;
|
selectedGroupIndex = widget.initialGroupIndex;
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,16 +46,17 @@ class _ChooseGroupViewState extends State<ChooseGroupView> {
|
|||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedGroup = index;
|
selectedGroupIndex = index;
|
||||||
});
|
});
|
||||||
|
|
||||||
Future.delayed(const Duration(milliseconds: 500), () {
|
Future.delayed(const Duration(milliseconds: 500), () {
|
||||||
|
if (!context.mounted) return;
|
||||||
Navigator.of(context).pop(widget.groups[index]);
|
Navigator.of(context).pop(widget.groups[index]);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: GroupTile(
|
child: GroupTile(
|
||||||
group: widget.groups[index],
|
group: widget.groups[index],
|
||||||
isHighlighted: selectedGroup == index,
|
isHighlighted: selectedGroupIndex == index,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user