Marco
1cb5ffb82b
This is another step to allow reconnecting after connection loss or browser closing. When the game is left with the X button on the bottom right, we will close the websocket connection, to let the server know, that we are gone. The server still has issues that prevent this from working flawlessly.
89 lines
2.3 KiB
Dart
89 lines
2.3 KiB
Dart
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';
|
|
import 'package:mchess/chess_bloc/promotion_bloc.dart';
|
|
import 'package:mchess/connection/ws_connection.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;
|
|
final UuidValue lobbyID;
|
|
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(
|
|
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,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () {
|
|
ServerConnection.getInstance().disconnectExistingConnection();
|
|
context.push('/');
|
|
},
|
|
child: const Icon(Icons.cancel),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> promotionDialogBuilder(BuildContext context, ChessColor color) {
|
|
return showDialog<void>(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (BuildContext context) {
|
|
return PromotionDialog(
|
|
sideColor: color,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class ChessGameArguments {
|
|
final UuidValue lobbyID;
|
|
final UuidValue playerID;
|
|
final String? passphrase;
|
|
|
|
ChessGameArguments({
|
|
required this.lobbyID,
|
|
required this.playerID,
|
|
required this.passphrase,
|
|
});
|
|
}
|