73 lines
2.3 KiB
Dart
73 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:mchess/chess_bloc/promotion_bloc.dart';
|
|
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) {
|
|
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: () {
|
|
Navigator.pop(context);
|
|
pieceChosen(ChessPieceClass.queen);
|
|
},
|
|
icon: SvgPicture.asset(chessPiecesAssets[ChessPieceAssetKey(
|
|
pieceClass: ChessPieceClass.queen, color: sideColor)]!),
|
|
iconSize: 200,
|
|
),
|
|
IconButton(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
pieceChosen(ChessPieceClass.rook);
|
|
},
|
|
icon: SvgPicture.asset(chessPiecesAssets[ChessPieceAssetKey(
|
|
pieceClass: ChessPieceClass.rook, color: sideColor)]!),
|
|
iconSize: 100,
|
|
),
|
|
IconButton(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
pieceChosen(ChessPieceClass.knight);
|
|
},
|
|
icon: SvgPicture.asset(chessPiecesAssets[ChessPieceAssetKey(
|
|
pieceClass: ChessPieceClass.knight, color: sideColor)]!),
|
|
iconSize: 10,
|
|
),
|
|
IconButton(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
pieceChosen(ChessPieceClass.bishop);
|
|
},
|
|
icon: SvgPicture.asset(chessPiecesAssets[ChessPieceAssetKey(
|
|
pieceClass: ChessPieceClass.bishop, color: sideColor)]!),
|
|
iconSize: iconSize,
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void pieceChosen(ChessPieceClass pieceClass) {
|
|
PromotionBloc.getInstance()
|
|
.add(PieceChosen(pieceClass: pieceClass, color: sideColor));
|
|
}
|
|
}
|