From 330aeed476c968dea44d8874344e26242faed919 Mon Sep 17 00:00:00 2001 From: Marco Date: Sun, 25 Dec 2022 20:30:42 +0100 Subject: [PATCH] Make ChessAppRouter a class. --- lib/chess/chess_app.dart | 6 ++++-- lib/utils/chess_router.dart | 34 ++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/chess/chess_app.dart b/lib/chess/chess_app.dart index c31a477..c1dacdd 100644 --- a/lib/chess/chess_app.dart +++ b/lib/chess/chess_app.dart @@ -14,8 +14,10 @@ class ChessApp extends StatelessWidget { child: BlocProvider( create: (_) => ChessBloc.getInstance(), child: MaterialApp.router( - theme: ThemeData.dark(useMaterial3: true), - routerConfig: router, + theme: ThemeData.dark( + useMaterial3: true, + ), + routerConfig: ChessAppRouter.getInstance().router, title: 'mChess v0.1.1337', ), ), diff --git a/lib/utils/chess_router.dart b/lib/utils/chess_router.dart index 8170df9..85fde93 100644 --- a/lib/utils/chess_router.dart +++ b/lib/utils/chess_router.dart @@ -2,15 +2,25 @@ import 'package:go_router/go_router.dart'; import 'package:mchess/pages/chess_game.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 ChessGame(), - ) - ], -); +class ChessAppRouter { + static final ChessAppRouter _instance = ChessAppRouter._internal(); + + ChessAppRouter._internal(); + + static ChessAppRouter getInstance() { + return _instance; + } + + final router = GoRouter( + routes: [ + GoRoute( + path: '/', + builder: (context, state) => const LobbySelector(), + ), + GoRoute( + path: '/play', + builder: (context, state) => const ChessGame(), + ) + ], + ); +}