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: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';
|
||||
|
||||
class GameResultView extends StatefulWidget {
|
||||
@@ -12,6 +15,30 @@ class GameResultView extends StatefulWidget {
|
||||
}
|
||||
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -26,32 +53,68 @@ class _GameResultViewState extends State<GameResultView> {
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: CustomTheme.boxColor,
|
||||
border: Border.all(color: CustomTheme.boxBorder),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"Select Winner",
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 10,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10,
|
||||
horizontal: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: CustomTheme.boxColor,
|
||||
border: Border.all(color: CustomTheme.boxBorder),
|
||||
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
|
||||
//TODO Implement Save button with snackbar to confirm save/show error
|
||||
CustomWidthButton(text: "Save", sizeRelativeToWidth: 0.95),
|
||||
],
|
||||
),
|
||||
),
|
||||
CustomWidthButton(
|
||||
text: "Save",
|
||||
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