2022-12-25 18:57:47 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2023-05-28 15:44:22 +00:00
|
|
|
import 'package:go_router/go_router.dart';
|
2022-12-25 18:57:47 +00:00
|
|
|
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
|
|
|
|
|
|
|
import 'package:mchess/chess/chess_board.dart';
|
|
|
|
import 'package:mchess/chess/turn_indicator_widget.dart';
|
|
|
|
import 'package:mchess/connection_cubit/connection_cubit.dart';
|
|
|
|
|
|
|
|
import 'package:mchess/connection/ws_connection.dart';
|
|
|
|
import 'package:mchess/utils/widgets/server_log_widget.dart';
|
2023-05-28 15:44:22 +00:00
|
|
|
import 'package:uuid/uuid.dart';
|
2022-12-25 18:57:47 +00:00
|
|
|
|
2023-05-28 12:54:46 +00:00
|
|
|
class ChessGame extends StatefulWidget {
|
2023-05-28 15:44:22 +00:00
|
|
|
final UuidValue playerID;
|
2023-06-02 21:28:40 +00:00
|
|
|
final UuidValue lobbyID;
|
|
|
|
const ChessGame({required this.playerID, required this.lobbyID, super.key});
|
2022-12-25 18:57:47 +00:00
|
|
|
|
2023-05-28 12:54:46 +00:00
|
|
|
@override
|
|
|
|
State<ChessGame> createState() => _ChessGameState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ChessGameState extends State<ChessGame> {
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2023-06-02 21:28:40 +00:00
|
|
|
ConnectionCubit.getInstance()
|
|
|
|
.connect(widget.playerID.uuid, widget.lobbyID.uuid);
|
2023-05-28 12:54:46 +00:00
|
|
|
}
|
|
|
|
|
2022-12-25 18:57:47 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2022-12-25 19:18:50 +00:00
|
|
|
body: Center(
|
|
|
|
child: FittedBox(
|
2022-12-25 18:57:47 +00:00
|
|
|
fit: BoxFit.contain,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
if (kDebugMode)
|
|
|
|
StreamBuilder(
|
|
|
|
stream: ServerConnection.getInstance().broadcast,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return ServerLogWidget(
|
|
|
|
snapshot.data ?? "<snapshot empty>",
|
|
|
|
textColor: Colors.white,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
margin: const EdgeInsets.all(20),
|
|
|
|
child: BlocBuilder<ChessBloc, ChessBoardState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
return ChessBoard(
|
|
|
|
bState: state,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (kDebugMode) const TurnIndicator(),
|
|
|
|
],
|
|
|
|
),
|
2022-12-25 19:18:50 +00:00
|
|
|
),
|
2022-12-25 18:57:47 +00:00
|
|
|
),
|
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
onPressed: () {
|
2023-05-28 15:44:22 +00:00
|
|
|
context.goNamed('lobbySelector');
|
2022-12-25 18:57:47 +00:00
|
|
|
},
|
2023-05-28 15:44:22 +00:00
|
|
|
child: const Icon(Icons.arrow_back),
|
2022-12-25 18:57:47 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|