mchess-client/lib/chessapp/chess_app.dart
Marco c04407ae67 Make chess work.
Remove sending the new move in moveHandler, in order to prevent a loop
move -> emit -> move ...

Handle incoming moves.

There still is a major bug. Sometimes random pieces move.
2022-12-14 23:17:31 +01:00

79 lines
2.6 KiB
Dart

import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mchess/chess_bloc/chess_bloc.dart';
import 'package:mchess/connection/ws_connection.dart';
import 'package:mchess/chessapp/chess_board.dart';
import 'package:mchess/connection_cubit/connection_cubit.dart';
class ChessApp extends StatelessWidget {
const ChessApp({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => ConnectionCubit.getInstance(),
child: 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(
child: FittedBox(
fit: BoxFit.contain,
child: Column(
children: [
Container(
margin: const EdgeInsets.all(20),
child: BlocProvider(
create: (_) => ChessBloc.getInstance(),
child: BlocBuilder<ChessBloc, ChessBoardState>(
builder: (context, state) {
return ChessBoard(
bState: state,
);
},
),
),
),
BlocBuilder<ConnectionCubit, ConnectionCubitState>(
builder: (context, state) {
return StreamBuilder(
stream: ServerConnection.getInstance().broadcast,
builder: (context, snapshot) {
return Text(
style: const TextStyle(color: Colors.white),
snapshot.data.toString());
},
);
},
)
],
),
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
ConnectionCubit.getInstance().reconnect();
},
child: const Icon(Icons.network_wifi),
),
),
),
);
}
}