Do some more restructuring. ChessApp is now the app. ChessGame is the widget that contains the game and board.
This commit is contained in:
parent
80a24bafd6
commit
4626084abd
27
lib/chess/chess_app.dart
Normal file
27
lib/chess/chess_app.dart
Normal file
@ -0,0 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
||||
import 'package:mchess/connection_cubit/connection_cubit.dart';
|
||||
import 'package:mchess/utils/chess_router.dart';
|
||||
|
||||
class ChessApp extends StatelessWidget {
|
||||
const ChessApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => ConnectionCubit.getInstance(),
|
||||
child: BlocProvider(
|
||||
create: (_) => ChessBloc.getInstance(),
|
||||
child: Container(
|
||||
color: Colors.amber,
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: MaterialApp.router(
|
||||
routerConfig: router,
|
||||
title: 'mChess v0.1.1337',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
||||
import 'package:mchess/chess_bloc/chess_events.dart';
|
||||
|
@ -1,17 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mchess/utils/chess_router.dart';
|
||||
import 'package:mchess/chess/chess_app.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp.router(
|
||||
routerConfig: router,
|
||||
);
|
||||
}
|
||||
runApp(const ChessApp());
|
||||
}
|
||||
|
69
lib/pages/chess_game.dart
Normal file
69
lib/pages/chess_game.dart
Normal file
@ -0,0 +1,69 @@
|
||||
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 StatelessWidget {
|
||||
const ChessGame({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return 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: 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().reconnect();
|
||||
},
|
||||
child: const Icon(Icons.network_wifi),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mchess/pages/chess_app.dart';
|
||||
import 'package:mchess/pages/chess_game.dart';
|
||||
import 'package:mchess/pages/lobby_selector.dart';
|
||||
|
||||
final router = GoRouter(
|
||||
@ -10,7 +10,7 @@ final router = GoRouter(
|
||||
),
|
||||
GoRoute(
|
||||
path: '/play',
|
||||
builder: (context, state) => const ChessApp(),
|
||||
builder: (context, state) => const ChessGame(),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
@ -7,12 +7,12 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mchess/pages/chess_app.dart';
|
||||
import 'package:mchess/pages/chess_game.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const ChessApp());
|
||||
await tester.pumpWidget(const ChessGame());
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
|
Loading…
Reference in New Issue
Block a user