Select Git revision
discoveries.dart
-
Benoît Harrault authoredBenoît Harrault authored
game_end.dart 2.56 KiB
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:puissance4/cubit/game_cubit.dart';
import 'package:puissance4/models/game/game.dart';
import 'package:puissance4/ui/widgets/actions/button_game_quit.dart';
class GameEndWidget extends StatelessWidget {
const GameEndWidget({super.key});
@override
Widget build(BuildContext context) {
return BlocBuilder<GameCubit, GameState>(
builder: (BuildContext context, GameState gameState) {
final Game currentGame = gameState.currentGame;
final bool connected4 = currentGame.connected4();
final String player1ImageAsset = (currentGame.currentPlayer == 1 && connected4)
? 'assets/ui/game_win.png'
: (currentGame.currentPlayer == 2 && connected4)
? 'assets/ui/game_fail.png'
: 'assets/ui/game_draw.png';
final String player2ImageAsset = (currentGame.currentPlayer == 2 && connected4)
? 'assets/ui/game_win.png'
: (currentGame.currentPlayer == 1 && connected4)
? 'assets/ui/game_fail.png'
: 'assets/ui/game_draw.png';
final Image player1Image = Image(
image: AssetImage(player1ImageAsset),
fit: BoxFit.fill,
);
final Image player2Image = Image(
image: AssetImage(player2ImageAsset),
fit: BoxFit.fill,
);
return Container(
margin: const EdgeInsets.all(2),
padding: const EdgeInsets.all(2),
child: Table(
defaultColumnWidth: const IntrinsicColumnWidth(),
defaultVerticalAlignment: TableCellVerticalAlignment.bottom,
children: [
TableRow(
children: [
Column(children: [player1Image]),
Column(children: [player1Image]),
Column(
children: [
currentGame.animationInProgress
? Image(
image: const AssetImage('assets/ui/placeholder.png'),
fit: BoxFit.fill,
)
: SizedBox.square(
dimension: 70,
child: QuitGameButton(),
),
],
),
Column(children: [player2Image]),
Column(children: [player2Image]),
],
),
],
),
);