2022-11-12 21:55:45 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-11-13 00:03:47 +00:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
2022-11-13 13:28:30 +00:00
|
|
|
import 'package:mchess/connection/ws_connection.dart';
|
2022-11-12 21:55:45 +00:00
|
|
|
|
2022-11-13 13:28:30 +00:00
|
|
|
import 'package:mchess/chessapp/chess_board.dart';
|
2022-11-12 21:55:45 +00:00
|
|
|
|
|
|
|
class ChessApp extends StatelessWidget {
|
|
|
|
const ChessApp({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
title: 'mChess',
|
|
|
|
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),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Center(
|
2022-11-19 10:37:15 +00:00
|
|
|
child: FittedBox(
|
|
|
|
fit: BoxFit.contain,
|
2022-11-13 13:28:30 +00:00
|
|
|
child: Column(
|
2022-11-19 10:37:15 +00:00
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
margin: const EdgeInsets.all(20),
|
|
|
|
child: BlocProvider(
|
|
|
|
create: (_) => ChessBloc.getInstance(),
|
|
|
|
child: BlocBuilder<ChessBloc, ChessBoardState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
return ChessBoard(
|
|
|
|
bState: state,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-11-13 13:28:30 +00:00
|
|
|
),
|
|
|
|
),
|
2022-11-19 10:37:15 +00:00
|
|
|
StreamBuilder(
|
|
|
|
stream: ServerConnection.getInstance().channel.stream,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return Text(
|
|
|
|
style: const TextStyle(color: Colors.white),
|
|
|
|
snapshot.data.toString());
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
2022-11-12 21:55:45 +00:00
|
|
|
),
|
2022-11-19 10:37:15 +00:00
|
|
|
),
|
|
|
|
),
|
2022-11-12 21:55:45 +00:00
|
|
|
),
|
2022-11-19 12:24:38 +00:00
|
|
|
floatingActionButton: const FloatingActionButton(
|
|
|
|
onPressed: reconnect,
|
|
|
|
child: Icon(Icons.connect_without_contact),
|
|
|
|
),
|
2022-11-12 21:55:45 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-11-19 12:24:38 +00:00
|
|
|
|
|
|
|
void reconnect() {
|
|
|
|
ServerConnection.getInstance().reconnect();
|
|
|
|
}
|