Implement basic logic and UI for selecting game winners in GameResultView
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
import 'package:game_tracker/data/dto/game.dart';
|
||||||
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
||||||
|
|
||||||
class GameResultView extends StatefulWidget {
|
class GameResultView extends StatefulWidget {
|
||||||
@@ -12,6 +15,30 @@ class GameResultView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _GameResultViewState extends State<GameResultView> {
|
class _GameResultViewState extends State<GameResultView> {
|
||||||
|
late final List<Player> allPlayers;
|
||||||
|
final exampleGame = Game(
|
||||||
|
name: "Test Game",
|
||||||
|
players: [
|
||||||
|
Player(name: "Petrus"),
|
||||||
|
Player(name: "Peter"),
|
||||||
|
Player(name: "Petra"),
|
||||||
|
],
|
||||||
|
group: Group(
|
||||||
|
name: "Die Petris",
|
||||||
|
members: [
|
||||||
|
Player(name: "Petralia"),
|
||||||
|
Player(name: "Petrenlia"),
|
||||||
|
Player(name: "Petrumlia"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
allPlayers = getAllPlayers(exampleGame);
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -26,32 +53,68 @@ class _GameResultViewState extends State<GameResultView> {
|
|||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
),
|
),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Container(
|
child: Column(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
children: [
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
Expanded(
|
||||||
decoration: BoxDecoration(
|
child: Container(
|
||||||
color: CustomTheme.boxColor,
|
margin: const EdgeInsets.symmetric(
|
||||||
border: Border.all(color: CustomTheme.boxBorder),
|
horizontal: 12,
|
||||||
borderRadius: BorderRadius.circular(12),
|
vertical: 10,
|
||||||
),
|
),
|
||||||
child: const Column(
|
padding: const EdgeInsets.symmetric(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
vertical: 10,
|
||||||
children: [
|
horizontal: 10,
|
||||||
Text(
|
),
|
||||||
"Select Winner",
|
decoration: BoxDecoration(
|
||||||
style: const TextStyle(
|
color: CustomTheme.boxColor,
|
||||||
fontSize: 18,
|
border: Border.all(color: CustomTheme.boxBorder),
|
||||||
fontWeight: FontWeight.bold,
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
"Select Winner:",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: allPlayers.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
//TODO: Implement Custom RadioListTile, see text_icon_list_tile
|
||||||
|
return RadioListTile<Player>(
|
||||||
|
title: Text(allPlayers[index].name),
|
||||||
|
value: allPlayers[index],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
//TODO: Add FutureBuilder
|
),
|
||||||
//TODO: Implement ListView.builder with RadioListTiles and Players from Game
|
CustomWidthButton(
|
||||||
//TODO Implement Save button with snackbar to confirm save/show error
|
text: "Save",
|
||||||
CustomWidthButton(text: "Save", sizeRelativeToWidth: 0.95),
|
sizeRelativeToWidth: 0.95,
|
||||||
],
|
onPressed: null,
|
||||||
),
|
),
|
||||||
|
SizedBox(height: 10),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Player> getAllPlayers(Game game) {
|
||||||
|
if (game.group == null && game.players != null) {
|
||||||
|
return [...game.players!];
|
||||||
|
} else if (game.group != null && game.players != null) {
|
||||||
|
return [...game.players!, ...game.group!.members];
|
||||||
|
}
|
||||||
|
return [...game.group!.members];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user