mchess-client/lib/pages/chess_app.dart

79 lines
2.7 KiB
Dart
Raw Normal View History

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';
2022-12-25 15:16:23 +00:00
import 'package:mchess/chess/chess_board.dart';
import 'package:mchess/chess/turn_indicator_widget.dart';
import 'package:mchess/connection_cubit/connection_cubit.dart';
2022-12-25 15:16:23 +00:00
import 'package:mchess/connection/ws_connection.dart';
import 'package:mchess/utils/widgets/server_log_widget.dart';
2022-12-18 00:04:08 +00:00
class ChessApp extends StatelessWidget {
const ChessApp({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => ConnectionCubit.getInstance(),
2022-12-18 00:04:08 +00:00
child: BlocProvider(
create: (_) => ChessBloc.getInstance(),
child: MaterialApp(
title: 'mChess v0.1.1337',
2022-12-18 00:04:08 +00:00
home: Scaffold(
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromARGB(255, 20, 20, 20),
Color.fromARGB(255, 30, 30, 30),
Color.fromARGB(255, 40, 40, 40),
],
),
),
2022-12-18 00:04:08 +00:00
child: Center(
child: FittedBox(
fit: BoxFit.contain,
2022-12-18 00:04:08 +00:00
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),
2022-12-18 00:04:08 +00:00
child: BlocBuilder<ChessBloc, ChessBoardState>(
builder: (context, state) {
return ChessBoard(
bState: state,
);
},
2022-11-19 10:37:15 +00:00
),
),
if (kDebugMode) const TurnIndicator(),
],
),
2022-12-18 00:04:08 +00:00
)),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
ConnectionCubit.getInstance().reconnect();
},
child: const Icon(Icons.network_wifi),
2022-11-19 10:37:15 +00:00
),
),
2022-11-19 12:24:38 +00:00
),
),
);
}
}