Pop promotion dialog with context.pop()

This commit is contained in:
Marco 2023-12-25 02:07:03 +01:00
parent abf322572d
commit 17ac437f5b

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';
import 'package:mchess/chess_bloc/promotion_bloc.dart';
import 'package:mchess/utils/chess_utils.dart';
@ -26,35 +27,31 @@ class PromotionDialog extends StatelessWidget {
children: [
IconButton(
onPressed: () {
Navigator.pop(context);
pieceChosen(ChessPieceClass.queen);
pieceChosen(context, ChessPieceClass.queen);
},
icon: SvgPicture.asset(chessPiecesAssets[ChessPieceAssetKey(
pieceClass: ChessPieceClass.queen, color: sideColor)]!),
iconSize: 200,
iconSize: iconSize,
),
IconButton(
onPressed: () {
Navigator.pop(context);
pieceChosen(ChessPieceClass.rook);
pieceChosen(context, ChessPieceClass.rook);
},
icon: SvgPicture.asset(chessPiecesAssets[ChessPieceAssetKey(
pieceClass: ChessPieceClass.rook, color: sideColor)]!),
iconSize: 100,
iconSize: iconSize,
),
IconButton(
onPressed: () {
Navigator.pop(context);
pieceChosen(ChessPieceClass.knight);
pieceChosen(context, ChessPieceClass.knight);
},
icon: SvgPicture.asset(chessPiecesAssets[ChessPieceAssetKey(
pieceClass: ChessPieceClass.knight, color: sideColor)]!),
iconSize: 10,
iconSize: iconSize,
),
IconButton(
onPressed: () {
Navigator.pop(context);
pieceChosen(ChessPieceClass.bishop);
pieceChosen(context, ChessPieceClass.bishop);
},
icon: SvgPicture.asset(chessPiecesAssets[ChessPieceAssetKey(
pieceClass: ChessPieceClass.bishop, color: sideColor)]!),
@ -65,7 +62,8 @@ class PromotionDialog extends StatelessWidget {
);
}
void pieceChosen(ChessPieceClass pieceClass) {
void pieceChosen(BuildContext context, ChessPieceClass pieceClass) {
context.pop();
PromotionBloc.getInstance()
.add(PieceChosen(pieceClass: pieceClass, color: sideColor));
}