2023-07-01 07:29:43 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_svg/svg.dart';
|
2023-12-25 01:07:03 +00:00
|
|
|
import 'package:go_router/go_router.dart';
|
2023-07-03 17:41:12 +00:00
|
|
|
import 'package:mchess/chess_bloc/promotion_bloc.dart';
|
2023-07-01 07:29:43 +00:00
|
|
|
import 'package:mchess/utils/chess_utils.dart';
|
|
|
|
|
|
|
|
class PromotionDialog extends StatelessWidget {
|
|
|
|
final ChessColor sideColor;
|
|
|
|
const PromotionDialog({required this.sideColor, super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-07-03 17:41:12 +00:00
|
|
|
double windowWidth = MediaQuery.of(context).size.width;
|
|
|
|
double windowHeight = MediaQuery.of(context).size.height;
|
|
|
|
double iconSize;
|
|
|
|
|
|
|
|
if (windowWidth < windowHeight) {
|
|
|
|
iconSize = 0.15 * windowWidth;
|
|
|
|
} else {
|
|
|
|
iconSize = 0.15 * windowHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Dialog(
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
children: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
2023-12-25 01:07:03 +00:00
|
|
|
pieceChosen(context, ChessPieceClass.queen);
|
2023-07-03 17:41:12 +00:00
|
|
|
},
|
|
|
|
icon: SvgPicture.asset(chessPiecesAssets[ChessPieceAssetKey(
|
|
|
|
pieceClass: ChessPieceClass.queen, color: sideColor)]!),
|
2023-12-25 01:07:03 +00:00
|
|
|
iconSize: iconSize,
|
2023-07-03 17:41:12 +00:00
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
2023-12-25 01:07:03 +00:00
|
|
|
pieceChosen(context, ChessPieceClass.rook);
|
2023-07-03 17:41:12 +00:00
|
|
|
},
|
|
|
|
icon: SvgPicture.asset(chessPiecesAssets[ChessPieceAssetKey(
|
|
|
|
pieceClass: ChessPieceClass.rook, color: sideColor)]!),
|
2023-12-25 01:07:03 +00:00
|
|
|
iconSize: iconSize,
|
2023-07-01 07:29:43 +00:00
|
|
|
),
|
2023-07-03 17:41:12 +00:00
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
2023-12-25 01:07:03 +00:00
|
|
|
pieceChosen(context, ChessPieceClass.knight);
|
2023-07-03 17:41:12 +00:00
|
|
|
},
|
|
|
|
icon: SvgPicture.asset(chessPiecesAssets[ChessPieceAssetKey(
|
|
|
|
pieceClass: ChessPieceClass.knight, color: sideColor)]!),
|
2023-12-25 01:07:03 +00:00
|
|
|
iconSize: iconSize,
|
2023-07-03 17:41:12 +00:00
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
2023-12-25 01:07:03 +00:00
|
|
|
pieceChosen(context, ChessPieceClass.bishop);
|
2023-07-03 17:41:12 +00:00
|
|
|
},
|
|
|
|
icon: SvgPicture.asset(chessPiecesAssets[ChessPieceAssetKey(
|
|
|
|
pieceClass: ChessPieceClass.bishop, color: sideColor)]!),
|
|
|
|
iconSize: iconSize,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2023-07-01 07:29:43 +00:00
|
|
|
);
|
|
|
|
}
|
2023-07-03 17:41:12 +00:00
|
|
|
|
2023-12-25 01:07:03 +00:00
|
|
|
void pieceChosen(BuildContext context, ChessPieceClass pieceClass) {
|
|
|
|
context.pop();
|
2023-07-03 17:41:12 +00:00
|
|
|
PromotionBloc.getInstance()
|
|
|
|
.add(PieceChosen(pieceClass: pieceClass, color: sideColor));
|
|
|
|
}
|
2023-07-01 07:29:43 +00:00
|
|
|
}
|