CreateGameView erstellen #67
@@ -6,12 +6,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 initialGroupIndex;
|
final String initialGroupId;
|
||||||
|
|
||||||
const ChooseGroupView({
|
const ChooseGroupView({
|
||||||
super.key,
|
super.key,
|
||||||
required this.groups,
|
required this.groups,
|
||||||
required this.initialGroupIndex,
|
required this.initialGroupId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -19,13 +19,15 @@ class ChooseGroupView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ChooseGroupViewState extends State<ChooseGroupView> {
|
class _ChooseGroupViewState extends State<ChooseGroupView> {
|
||||||
late int selectedGroupIndex;
|
late String selectedGroupId;
|
||||||
final TextEditingController controller = TextEditingController();
|
final TextEditingController controller = TextEditingController();
|
||||||
final String hintText = 'Group Name';
|
final String hintText = 'Group Name';
|
||||||
|
late final List<Group> filteredGroups;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
selectedGroupIndex = widget.initialGroupIndex;
|
selectedGroupId = widget.initialGroupId;
|
||||||
|
filteredGroups = [...widget.groups];
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,9 +42,11 @@ class _ChooseGroupViewState extends State<ChooseGroupView> {
|
|||||||
icon: const Icon(Icons.arrow_back_ios),
|
icon: const Icon(Icons.arrow_back_ios),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop(
|
Navigator.of(context).pop(
|
||||||
selectedGroupIndex == -1
|
selectedGroupId == ''
|
||||||
? null
|
? null
|
||||||
: widget.groups[selectedGroupIndex],
|
: widget.groups.firstWhere(
|
||||||
|
(group) => group.id == selectedGroupId,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -56,26 +60,34 @@ class _ChooseGroupViewState extends State<ChooseGroupView> {
|
|||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
child: CustomSearchBar(controller: controller, hintText: hintText),
|
child: CustomSearchBar(
|
||||||
|
controller: controller,
|
||||||
|
hintText: hintText,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
filterGroups(value);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
padding: const EdgeInsets.only(bottom: 85),
|
padding: const EdgeInsets.only(bottom: 85),
|
||||||
itemCount: widget.groups.length,
|
itemCount: filteredGroups.length,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (selectedGroupIndex == index) {
|
if (selectedGroupId != filteredGroups[index].id) {
|
||||||
|
flixcoo marked this conversation as resolved
|
|||||||
selectedGroupIndex = -1;
|
selectedGroupId = filteredGroups[index].id;
|
||||||
} else {
|
} else {
|
||||||
selectedGroupIndex = index;
|
selectedGroupId = '';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: GroupTile(
|
child: GroupTile(
|
||||||
group: widget.groups[index],
|
group: filteredGroups[index],
|
||||||
isHighlighted: selectedGroupIndex == index,
|
isHighlighted: selectedGroupId == filteredGroups[index].id,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -85,4 +97,22 @@ class _ChooseGroupViewState extends State<ChooseGroupView> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Filters the groups based on the search query.
|
||||||
|
/// TODO: Maybe implement also targetting player names?
|
||||||
|
void filterGroups(String query) {
|
||||||
|
setState(() {
|
||||||
|
if (query.isEmpty) {
|
||||||
|
filteredGroups.clear();
|
||||||
|
filteredGroups.addAll(widget.groups);
|
||||||
|
} else {
|
||||||
|
filteredGroups.clear();
|
||||||
|
filteredGroups.addAll(
|
||||||
|
widget.groups.where(
|
||||||
|
(group) => group.name.toLowerCase().contains(query.toLowerCase()),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
|
|
||||||
/// The index of the currently selected group in [groupsList] to mark it in
|
/// The index of the currently selected group in [groupsList] to mark it in
|
||||||
/// the [ChooseGroupView]
|
/// the [ChooseGroupView]
|
||||||
int selectedGroupIndex = -1;
|
String selectedGroupId = '';
|
||||||
|
|
||||||
/// The currently selected ruleset
|
/// The currently selected ruleset
|
||||||
Ruleset? selectedRuleset;
|
Ruleset? selectedRuleset;
|
||||||
@@ -189,13 +189,11 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => ChooseGroupView(
|
builder: (context) => ChooseGroupView(
|
||||||
groups: groupsList,
|
groups: groupsList,
|
||||||
initialGroupIndex: selectedGroupIndex,
|
initialGroupId: selectedGroupId,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
selectedGroupIndex = groupsList.indexWhere(
|
selectedGroupId = selectedGroup?.id ?? '';
|
||||||
(g) => g.id == selectedGroup?.id,
|
|
||||||
);
|
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user
Hier bitte ohne Punkt, das hatten wir ja gesagt, und wir müssen uns darauf einigen ob der Titel infos erhält, oder nur keywords wie info/error, weil ich das bis jetzt so gemacht habe.
Sonst passt so
Wenn der Titel keine Infos enthalten soll, würd ich daraus n enum Attribut machen damit der je nach enum gesetzt wird (Icon und Titel)
ja findste mit oder ohne richtigen Title besser?
ist mir auch egal, lass es so oder nicht. Wenn du es mit Info/Error im Titel willst, mach am besten das einmal temporär in den Titel und dann nen Issue für Änderung der anderen Titel in eine enum Version oder halt eine Version mit aussagekräftigem Titel.
Aber auf jeden Fall den Punkt weg machen am Ende von Message
dann approve ich
erledigt