Marco
1cb5ffb82b
This is another step to allow reconnecting after connection loss or browser closing. When the game is left with the X button on the bottom right, we will close the websocket connection, to let the server know, that we are gone. The server still has issues that prevent this from working flawlessly.
61 lines
1.5 KiB
Dart
61 lines
1.5 KiB
Dart
import 'package:go_router/go_router.dart';
|
|
import 'package:mchess/connection/ws_connection.dart';
|
|
import 'package:mchess/pages/chess_game.dart';
|
|
import 'package:mchess/pages/join_game.dart';
|
|
import 'package:mchess/pages/lobby_selector.dart';
|
|
import 'package:mchess/pages/host_game.dart';
|
|
import 'package:mchess/pages/prepare_random_game.dart';
|
|
|
|
class ChessAppRouter {
|
|
static final ChessAppRouter _instance = ChessAppRouter._internal();
|
|
|
|
ChessAppRouter._internal();
|
|
|
|
static ChessAppRouter getInstance() {
|
|
return _instance;
|
|
}
|
|
|
|
final router = GoRouter(
|
|
routes: [
|
|
GoRoute(
|
|
path: '/',
|
|
name: 'lobbySelector',
|
|
builder: (context, state) {
|
|
return const LobbySelector();
|
|
},
|
|
),
|
|
GoRoute(
|
|
path: '/prepareRandom',
|
|
name: 'prepareRandom',
|
|
builder: (context, state) {
|
|
return const PrepareRandomGameWidget();
|
|
}),
|
|
GoRoute(
|
|
path: '/host',
|
|
name: 'host',
|
|
builder: (context, state) {
|
|
return const HostGameWidget();
|
|
}),
|
|
GoRoute(
|
|
path: '/join',
|
|
name: 'join',
|
|
builder: (context, state) {
|
|
return const JoinGameWidget();
|
|
}),
|
|
GoRoute(
|
|
path: '/game',
|
|
name: 'game',
|
|
builder: (context, state) {
|
|
var args = state.extra as ChessGameArguments;
|
|
|
|
return ChessGame(
|
|
lobbyID: args.lobbyID,
|
|
playerID: args.playerID,
|
|
passphrase: args.passphrase,
|
|
);
|
|
},
|
|
)
|
|
],
|
|
);
|
|
}
|