mchess-client/lib/utils/chess_router.dart
Marco adf8c86692 Make many changes
1. A game is only identified by a passphrase (not a lobby id)
2. We can store multiple passphrase/playerID combinations
2024-05-20 15:34:20 +02:00

57 lines
1.5 KiB
Dart

import 'dart:developer';
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:mchess/pages/join_game_handle_widget.dart';
import 'package:mchess/pages/lobby_selector.dart';
import 'package:mchess/pages/create_game_widget.dart';
import 'package:mchess/utils/passphrase.dart';
final navigatorKey = GlobalKey<NavigatorState>();
class ChessAppRouter {
static final ChessAppRouter _instance = ChessAppRouter._internal();
ChessAppRouter._internal();
static ChessAppRouter getInstance() {
return _instance;
}
final router = GoRouter(
navigatorKey: navigatorKey,
debugLogDiagnostics: true,
routes: [
GoRoute(
path: '/',
name: 'lobbySelector',
builder: (context, state) {
return const LobbySelector();
},
routes: [
GoRoute(
path: 'createGame',
name: 'createGame',
builder: (context, state) {
return const CreateGameWidget();
}),
GoRoute(
path: 'game/:phrase',
name: 'game',
builder: (context, state) {
var urlPhrase = state.pathParameters['phrase'];
if (urlPhrase == null) {
log('in /game route builder: url phrase null');
return const LobbySelector();
}
return JoinGameHandleWidget(
passphrase: urlPhrase.toPhraseWithSpaces());
},
)
],
),
],
);
}