Add GoRouter and do a lot of renaming.

This commit is contained in:
Marco 2022-12-25 16:16:23 +01:00
parent bff46e6f3d
commit 80a24bafd6
14 changed files with 88 additions and 20 deletions

View File

@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:mchess/chess_bloc/chess_bloc.dart';
import 'chess_square.dart';
import 'chess_utils.dart';
import '../utils/chess_utils.dart';
class ChessBoard extends StatelessWidget {
final ChessBoardState bState;

View File

@ -4,7 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mchess/chess_bloc/chess_bloc.dart';
import '../connection/ws_connection.dart';
import 'chess_utils.dart';
import '../utils/chess_utils.dart';
int messageIndex = 0;

View File

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mchess/chess_bloc/chess_bloc.dart';
import 'chess_utils.dart';
import '../utils/chess_utils.dart';
class TurnIndicator extends StatelessWidget {
const TurnIndicator({super.key});

View File

@ -1,6 +1,6 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mchess/chess_bloc/chess_events.dart';
import 'package:mchess/chessapp/chess_utils.dart';
import 'package:mchess/utils/chess_utils.dart';
import 'dart:developer';
class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {

View File

@ -1,4 +1,4 @@
import 'package:mchess/chessapp/chess_utils.dart';
import 'package:mchess/utils/chess_utils.dart';
abstract class ChessEvent {}

View File

@ -4,7 +4,7 @@ import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:mchess/chess_bloc/chess_bloc.dart';
import 'package:mchess/chess_bloc/chess_events.dart';
import 'package:mchess/chessapp/chess_utils.dart';
import 'package:mchess/utils/chess_utils.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
class ServerConnection {

View File

@ -1,6 +1,17 @@
import 'package:flutter/material.dart';
import 'chessapp/chess_app.dart';
import 'package:mchess/utils/chess_router.dart';
void main() {
runApp(const ChessApp());
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: router,
);
}
}

View File

@ -3,12 +3,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mchess/chess_bloc/chess_bloc.dart';
import 'package:mchess/chessapp/chess_board.dart';
import 'package:mchess/chessapp/turn_indicator_widget.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 '../connection/ws_connection.dart';
import '../utils/widgets/server_log_widget.dart';
import 'package:mchess/connection/ws_connection.dart';
import 'package:mchess/utils/widgets/server_log_widget.dart';
class ChessApp extends StatelessWidget {
const ChessApp({super.key});

View File

@ -0,0 +1,19 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
class LobbySelector extends StatelessWidget {
const LobbySelector({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: TextButton(
onPressed: () {
context.go("/play");
},
child: const Text('Random lobby'),
)),
);
}
}

View File

@ -0,0 +1,16 @@
import 'package:go_router/go_router.dart';
import 'package:mchess/pages/chess_app.dart';
import 'package:mchess/pages/lobby_selector.dart';
final router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) => const LobbySelector(),
),
GoRoute(
path: '/play',
builder: (context, state) => const ChessApp(),
)
],
);

View File

@ -107,14 +107,27 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
go_router:
dependency: "direct main"
description:
name: go_router
sha256: "788a89932142b0059c319e3153e73308e0fc8bbab78e9a66b0128423090c4e01"
url: "https://pub.dev"
source: hosted
version: "6.0.0"
js:
dependency: transitive
description:
name: js
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
sha256: "323b7c70073cccf6b9b8d8b334be418a3293cfb612a560dc2737160a37bf61bd"
url: "https://pub.dev"
source: hosted
version: "0.6.5"
version: "0.6.6"
lints:
dependency: transitive
description:
@ -123,14 +136,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
logging:
dependency: transitive
description:
name: logging
sha256: c0bbfe94d46aedf9b8b3e695cf3bd48c8e14b35e3b2c639e0aa7755d589ba946
url: "https://pub.dev"
source: hosted
version: "1.1.0"
matcher:
dependency: transitive
description:
name: matcher
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
sha256: c94db23593b89766cda57aab9ac311e3616cf87c6fa4e9749df032f66f30dcb8
url: "https://pub.dev"
source: hosted
version: "0.12.13"
version: "0.12.14"
material_color_utilities:
dependency: transitive
description:
@ -252,10 +273,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
sha256: c9282698e2982b6c3817037554e52f99d4daba493e8028f8112a83d68ccd0b12
url: "https://pub.dev"
source: hosted
version: "0.4.16"
version: "0.4.17"
typed_data:
dependency: transitive
description:
@ -290,4 +311,4 @@ packages:
version: "6.2.2"
sdks:
dart: ">=2.19.0-392.0.dev <4.0.0"
flutter: ">=2.11.0-0.1.pre"
flutter: ">=3.3.0"

View File

@ -39,6 +39,7 @@ dependencies:
flutter_bloc: ^8.1.1
quiver: ^3.1.0
web_socket_channel: ^2.2.0
go_router: ^6.0.0
dev_dependencies:
flutter_test:

View File

@ -7,7 +7,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mchess/chessapp/chess_app.dart';
import 'package:mchess/pages/chess_app.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {