69 lines
2.0 KiB
Dart
69 lines
2.0 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
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';
|
|
|
|
class ChessGame extends StatefulWidget {
|
|
const ChessGame({super.key});
|
|
|
|
@override
|
|
State<ChessGame> createState() => _ChessGameState();
|
|
}
|
|
|
|
class _ChessGameState extends State<ChessGame> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
ConnectionCubit.getInstance().connect();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Center(
|
|
child: FittedBox(
|
|
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(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () {
|
|
ConnectionCubit.getInstance().connect();
|
|
},
|
|
child: const Icon(Icons.network_wifi),
|
|
),
|
|
);
|
|
}
|
|
}
|