Fix bug with missing queryParams, assign unique ids for all pathParams
This commit is contained in:
parent
ea47695847
commit
c45e1fc77e
@ -31,7 +31,7 @@ class ScreenPaths {
|
|||||||
static String _appendToCurrentPath(String newPath) {
|
static String _appendToCurrentPath(String newPath) {
|
||||||
final newPathUri = Uri.parse(newPath);
|
final newPathUri = Uri.parse(newPath);
|
||||||
final currentUri = appRouter.routeInformationProvider.value.uri;
|
final currentUri = appRouter.routeInformationProvider.value.uri;
|
||||||
Map<String, dynamic> params = Map.of(newPathUri.queryParameters);
|
Map<String, dynamic> params = Map.of(currentUri.queryParameters);
|
||||||
params.addAll(newPathUri.queryParameters);
|
params.addAll(newPathUri.queryParameters);
|
||||||
Uri? loc = Uri(path: '${currentUri.path}/${newPathUri.path}'.replaceAll('//', '/'), queryParameters: params);
|
Uri? loc = Uri(path: '${currentUri.path}/${newPathUri.path}'.replaceAll('//', '/'), queryParameters: params);
|
||||||
return loc.toString();
|
return loc.toString();
|
||||||
@ -40,8 +40,8 @@ class ScreenPaths {
|
|||||||
|
|
||||||
// Routes that are used multiple times
|
// Routes that are used multiple times
|
||||||
AppRoute get _artifactRoute => AppRoute(
|
AppRoute get _artifactRoute => AppRoute(
|
||||||
'artifact/:id',
|
'artifact/:artifactId',
|
||||||
(s) => ArtifactDetailsScreen(artifactId: s.pathParameters['id']!),
|
(s) => ArtifactDetailsScreen(artifactId: s.pathParameters['artifactId']!),
|
||||||
);
|
);
|
||||||
|
|
||||||
AppRoute get _timelineRoute {
|
AppRoute get _timelineRoute {
|
||||||
@ -55,9 +55,7 @@ AppRoute get _collectionRoute {
|
|||||||
return AppRoute(
|
return AppRoute(
|
||||||
'collection',
|
'collection',
|
||||||
(s) => CollectionScreen(fromId: s.uri.queryParameters['id'] ?? ''),
|
(s) => CollectionScreen(fromId: s.uri.queryParameters['id'] ?? ''),
|
||||||
routes: [
|
routes: [_artifactRoute],
|
||||||
_artifactRoute,
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,11 +74,11 @@ final appRouter = GoRouter(
|
|||||||
_timelineRoute,
|
_timelineRoute,
|
||||||
_collectionRoute,
|
_collectionRoute,
|
||||||
AppRoute(
|
AppRoute(
|
||||||
'wonder/:type',
|
'wonder/:detailsType',
|
||||||
(s) {
|
(s) {
|
||||||
int tab = int.tryParse(s.uri.queryParameters['t'] ?? '') ?? 0;
|
int tab = int.tryParse(s.uri.queryParameters['t'] ?? '') ?? 0;
|
||||||
return WonderDetailsScreen(
|
return WonderDetailsScreen(
|
||||||
type: _parseWonderType(s.pathParameters['type']),
|
type: _parseWonderType(s.pathParameters['detailsType']),
|
||||||
tabIndex: tab,
|
tabIndex: tab,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -91,15 +89,15 @@ final appRouter = GoRouter(
|
|||||||
_collectionRoute,
|
_collectionRoute,
|
||||||
_artifactRoute,
|
_artifactRoute,
|
||||||
// Youtube Video
|
// Youtube Video
|
||||||
AppRoute('video/:id', (s) {
|
AppRoute('video/:videoId', (s) {
|
||||||
return FullscreenVideoViewer(id: s.pathParameters['id']!);
|
return FullscreenVideoViewer(id: s.pathParameters['videoId']!);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
AppRoute(
|
AppRoute(
|
||||||
'search/:type',
|
'search/:searchType',
|
||||||
(s) {
|
(s) {
|
||||||
return ArtifactSearchScreen(type: _parseWonderType(s.pathParameters['type']));
|
return ArtifactSearchScreen(type: _parseWonderType(s.pathParameters['searchType']));
|
||||||
},
|
},
|
||||||
routes: [
|
routes: [
|
||||||
_artifactRoute,
|
_artifactRoute,
|
||||||
@ -107,9 +105,11 @@ final appRouter = GoRouter(
|
|||||||
),
|
),
|
||||||
|
|
||||||
// Maps
|
// Maps
|
||||||
AppRoute('maps/:type', (s) {
|
AppRoute(
|
||||||
return FullscreenMapsViewer(type: _parseWonderType(s.pathParameters['type']));
|
'maps/:mapsType',
|
||||||
}),
|
(s) => FullscreenMapsViewer(
|
||||||
|
type: _parseWonderType(s.pathParameters['mapsType']),
|
||||||
|
)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
@ -150,7 +150,7 @@ String? _initialDeeplink;
|
|||||||
String? _handleRedirect(BuildContext context, GoRouterState state) {
|
String? _handleRedirect(BuildContext context, GoRouterState state) {
|
||||||
// Prevent anyone from navigating away from `/` if app is starting up.
|
// Prevent anyone from navigating away from `/` if app is starting up.
|
||||||
if (!appLogic.isBootstrapComplete && state.uri.path != ScreenPaths.splash) {
|
if (!appLogic.isBootstrapComplete && state.uri.path != ScreenPaths.splash) {
|
||||||
debugPrint('Redirecting from ${state.uri.path} to ${ScreenPaths.splash}');
|
debugPrint('Redirecting from ${state.uri.path} to ${ScreenPaths.splash}.');
|
||||||
_initialDeeplink ??= state.uri.toString();
|
_initialDeeplink ??= state.uri.toString();
|
||||||
return ScreenPaths.splash;
|
return ScreenPaths.splash;
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ String? _handleRedirect(BuildContext context, GoRouterState state) {
|
|||||||
debugPrint('Redirecting from ${state.uri.path} to ${ScreenPaths.home}');
|
debugPrint('Redirecting from ${state.uri.path} to ${ScreenPaths.home}');
|
||||||
return ScreenPaths.home;
|
return ScreenPaths.home;
|
||||||
}
|
}
|
||||||
debugPrint('Navigate to: ${state.uri.path}');
|
debugPrint('Navigate to: ${state.uri}');
|
||||||
return null; // do nothing
|
return null; // do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user