155 lines
4.2 KiB
Dart
155 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// App route paths
|
|
class AppRoutes {
|
|
static const String home = '/';
|
|
static const String matchDetails = '/match/:id';
|
|
static const String bookmakerDetails = '/bookmaker/:id';
|
|
static const String settings = '/settings';
|
|
}
|
|
|
|
/// Route configuration for Navigator 2.0
|
|
class AppRouterDelegate extends RouterDelegate<RouteInformation>
|
|
with ChangeNotifier, PopNavigatorRouterDelegateMixin<RouteInformation> {
|
|
@override
|
|
final GlobalKey<NavigatorState> navigatorKey;
|
|
|
|
String _currentPath = AppRoutes.home;
|
|
String? _matchId;
|
|
String? _bookmakerId;
|
|
|
|
AppRouterDelegate() : navigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
String get currentPath => _currentPath;
|
|
|
|
@override
|
|
RouteInformation? get currentConfiguration {
|
|
if (_matchId != null) {
|
|
return RouteInformation(
|
|
uri: Uri.parse('/match/$_matchId'),
|
|
);
|
|
}
|
|
if (_bookmakerId != null) {
|
|
return RouteInformation(
|
|
uri: Uri.parse('/bookmaker/$_bookmakerId'),
|
|
);
|
|
}
|
|
return RouteInformation(uri: Uri.parse(_currentPath));
|
|
}
|
|
|
|
@override
|
|
Future<void> setNewRoutePath(RouteInformation configuration) async {
|
|
final uri = configuration.uri;
|
|
|
|
if (uri.pathSegments.isEmpty) {
|
|
_currentPath = AppRoutes.home;
|
|
_matchId = null;
|
|
_bookmakerId = null;
|
|
} else if (uri.pathSegments.length == 2) {
|
|
if (uri.pathSegments[0] == 'match') {
|
|
_currentPath = AppRoutes.matchDetails;
|
|
_matchId = uri.pathSegments[1];
|
|
} else if (uri.pathSegments[0] == 'bookmaker') {
|
|
_currentPath = AppRoutes.bookmakerDetails;
|
|
_bookmakerId = uri.pathSegments[1];
|
|
}
|
|
} else if (uri.pathSegments.length == 1) {
|
|
if (uri.pathSegments[0] == 'settings') {
|
|
_currentPath = AppRoutes.settings;
|
|
}
|
|
}
|
|
|
|
notifyListeners();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Navigator(
|
|
key: navigatorKey,
|
|
pages: [
|
|
const MaterialPage(
|
|
key: ValueKey('HomePage'),
|
|
child: Placeholder(), // Replace with actual HomePage
|
|
),
|
|
if (_matchId != null)
|
|
MaterialPage(
|
|
key: ValueKey('MatchDetailsPage-$_matchId'),
|
|
child: Placeholder(), // Replace with MatchDetailsPage
|
|
),
|
|
if (_bookmakerId != null)
|
|
MaterialPage(
|
|
key: ValueKey('BookmakerDetailsPage-$_bookmakerId'),
|
|
child: Placeholder(), // Replace with BookmakerDetailsPage
|
|
),
|
|
if (_currentPath == AppRoutes.settings)
|
|
const MaterialPage(
|
|
key: ValueKey('SettingsPage'),
|
|
child: Placeholder(), // Replace with SettingsPage
|
|
),
|
|
],
|
|
onPopPage: (route, result) {
|
|
if (!route.didPop(result)) {
|
|
return false;
|
|
}
|
|
|
|
// Handle navigation state after pop
|
|
if (_matchId != null) {
|
|
_matchId = null;
|
|
notifyListeners();
|
|
} else if (_bookmakerId != null) {
|
|
_bookmakerId = null;
|
|
notifyListeners();
|
|
} else if (_currentPath == AppRoutes.settings) {
|
|
_currentPath = AppRoutes.home;
|
|
notifyListeners();
|
|
}
|
|
|
|
return true;
|
|
},
|
|
);
|
|
}
|
|
|
|
/// Navigate to match details
|
|
void navigateToMatchDetails(String matchId) {
|
|
_matchId = matchId;
|
|
_currentPath = AppRoutes.matchDetails;
|
|
notifyListeners();
|
|
}
|
|
|
|
/// Navigate to bookmaker details
|
|
void navigateToBookmakerDetails(String bookmakerId) {
|
|
_bookmakerId = bookmakerId;
|
|
_currentPath = AppRoutes.bookmakerDetails;
|
|
notifyListeners();
|
|
}
|
|
|
|
/// Navigate to settings
|
|
void navigateToSettings() {
|
|
_currentPath = AppRoutes.settings;
|
|
notifyListeners();
|
|
}
|
|
|
|
/// Navigate to home
|
|
void navigateToHome() {
|
|
_currentPath = AppRoutes.home;
|
|
_matchId = null;
|
|
_bookmakerId = null;
|
|
notifyListeners();
|
|
}
|
|
}
|
|
|
|
/// Route information parser for Navigator 2.0
|
|
class AppRouteInformationParser extends RouteInformationParser<RouteInformation> {
|
|
@override
|
|
Future<RouteInformation> parseRouteInformation(
|
|
RouteInformation routeInformation,
|
|
) async {
|
|
return routeInformation;
|
|
}
|
|
|
|
@override
|
|
RouteInformation? restoreRouteInformation(RouteInformation configuration) {
|
|
return configuration;
|
|
}
|
|
}
|