mchess-client/lib/pages/chess_game.dart

87 lines
2.2 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:mchess/chess_bloc/chess_bloc.dart';
import 'package:mchess/chess/chess_board.dart';
2023-07-01 07:29:43 +00:00
import 'package:mchess/chess_bloc/promotion_bloc.dart';
import 'package:mchess/utils/chess_utils.dart';
import 'package:mchess/utils/widgets/promotion_dialog.dart';
import 'package:uuid/uuid.dart';
class ChessGame extends StatefulWidget {
final UuidValue playerID;
2023-06-02 21:28:40 +00:00
final UuidValue lobbyID;
2023-06-29 23:49:18 +00:00
final String? passphrase;
const ChessGame(
{required this.playerID,
required this.lobbyID,
required this.passphrase,
super.key});
@override
State<ChessGame> createState() => _ChessGameState();
}
class _ChessGameState extends State<ChessGame> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
2023-07-01 07:29:43 +00:00
body: Center(
child: Container(
margin: const EdgeInsets.all(10),
child: BlocListener<PromotionBloc, PromotionState>(
listener: (context, state) {
if (state.showPromotionDialog) {
promotionDialogBuilder(context, state.colorMoved);
}
},
child: BlocBuilder<ChessBloc, ChessBoardState>(
builder: (context, state) {
return ChessBoard(
boardState: state,
);
},
),
2023-07-01 07:29:43 +00:00
),
2022-12-25 19:18:50 +00:00
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
2023-06-29 23:49:18 +00:00
context.push('/');
},
2023-06-29 23:49:18 +00:00
child: const Icon(Icons.cancel),
),
);
}
2023-07-01 07:29:43 +00:00
Future<void> promotionDialogBuilder(BuildContext context, ChessColor color) {
return showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return PromotionDialog(
sideColor: color,
);
},
);
}
}
2023-06-29 23:49:18 +00:00
class ChessGameArguments {
final UuidValue lobbyID;
final UuidValue playerID;
final String? passphrase;
ChessGameArguments({
required this.lobbyID,
required this.playerID,
required this.passphrase,
});
}