mchess-client/lib/utils/chess_router.dart

57 lines
1.5 KiB
Dart
Raw Permalink Normal View History

2024-05-19 19:18:47 +00:00
import 'dart:developer';
import 'package:flutter/widgets.dart';
2022-12-25 15:16:23 +00:00
import 'package:go_router/go_router.dart';
2024-05-19 19:18:47 +00:00
import 'package:mchess/pages/join_game_handle_widget.dart';
2022-12-25 15:16:23 +00:00
import 'package:mchess/pages/lobby_selector.dart';
2024-05-19 19:18:47 +00:00
import 'package:mchess/pages/create_game_widget.dart';
import 'package:mchess/utils/passphrase.dart';
2022-12-25 15:16:23 +00:00
final navigatorKey = GlobalKey<NavigatorState>();
2022-12-25 19:30:42 +00:00
class ChessAppRouter {
static final ChessAppRouter _instance = ChessAppRouter._internal();
ChessAppRouter._internal();
static ChessAppRouter getInstance() {
return _instance;
}
final router = GoRouter(
navigatorKey: navigatorKey,
2023-12-27 14:46:15 +00:00
debugLogDiagnostics: true,
2022-12-25 19:30:42 +00:00
routes: [
GoRoute(
path: '/',
name: 'lobbySelector',
builder: (context, state) {
return const LobbySelector();
},
2023-12-27 14:46:15 +00:00
routes: [
GoRoute(
2024-05-19 19:18:47 +00:00
path: 'createGame',
name: 'createGame',
2023-12-27 14:46:15 +00:00
builder: (context, state) {
2024-05-19 19:18:47 +00:00
return const CreateGameWidget();
2023-12-27 14:46:15 +00:00
}),
GoRoute(
2024-05-19 19:18:47 +00:00
path: 'game/:phrase',
2023-12-27 14:46:15 +00:00
name: 'game',
builder: (context, state) {
2024-05-19 19:18:47 +00:00
var urlPhrase = state.pathParameters['phrase'];
if (urlPhrase == null) {
log('in /game route builder: url phrase null');
return const LobbySelector();
}
2023-06-29 23:49:18 +00:00
2024-05-19 19:18:47 +00:00
return JoinGameHandleWidget(
passphrase: urlPhrase.toPhraseWithSpaces());
2023-12-27 14:46:15 +00:00
},
)
],
),
2022-12-25 19:30:42 +00:00
],
);
}