Change routing setup

This commit is contained in:
problematicconsumer
2024-02-11 13:47:08 +03:30
parent 0da4eced0a
commit 6a6e824ba2
6 changed files with 499 additions and 480 deletions

View File

@@ -50,29 +50,30 @@ GoRouter router(RouterRef ref) {
);
}
final tabLocations = [
const HomeRoute().location,
const ProxiesRoute().location,
const ConfigOptionsRoute().location,
const SettingsRoute().location,
const LogsOverviewRoute().location,
const AboutRoute().location,
];
int getCurrentIndex(BuildContext context) {
final String location = GoRouterState.of(context).uri.path;
if (location == const HomeRoute().location) return 0;
if (location.startsWith(const ProxiesRoute().location)) return 1;
if (location.startsWith(const LogsOverviewRoute().location)) return 2;
if (location.startsWith(const SettingsRoute().location)) return 3;
if (location.startsWith(const AboutRoute().location)) return 4;
var index = 0;
for (final tab in tabLocations.sublist(1)) {
index++;
if (location.startsWith(tab)) return index;
}
return 0;
}
void switchTab(int index, BuildContext context) {
switch (index) {
case 0:
const HomeRoute().go(context);
case 1:
const ProxiesRoute().go(context);
case 2:
const LogsOverviewRoute().go(context);
case 3:
const SettingsRoute().go(context);
case 4:
const AboutRoute().go(context);
}
assert(index >= 0 && index < tabLocations.length);
final location = tabLocations[index];
return context.go(location);
}
@riverpod

View File

@@ -43,18 +43,14 @@ GlobalKey<NavigatorState>? _dynamicRootKey =
path: "profiles/:id",
name: ProfileDetailsRoute.name,
),
TypedGoRoute<LogsOverviewRoute>(
path: "logs",
name: LogsOverviewRoute.name,
TypedGoRoute<ConfigOptionsRoute>(
path: "config-options",
name: ConfigOptionsRoute.name,
),
TypedGoRoute<SettingsRoute>(
path: "settings",
name: SettingsRoute.name,
routes: [
TypedGoRoute<ConfigOptionsRoute>(
path: "config-options",
name: ConfigOptionsRoute.name,
),
TypedGoRoute<PerAppProxyRoute>(
path: "per-app-proxy",
name: PerAppProxyRoute.name,
@@ -65,6 +61,10 @@ GlobalKey<NavigatorState>? _dynamicRootKey =
),
],
),
TypedGoRoute<LogsOverviewRoute>(
path: "logs",
name: LogsOverviewRoute.name,
),
TypedGoRoute<AboutRoute>(
path: "about",
name: AboutRoute.name,
@@ -114,24 +114,24 @@ class MobileWrapperRoute extends ShellRouteData {
path: "/proxies",
name: ProxiesRoute.name,
),
TypedGoRoute<LogsOverviewRoute>(
path: "/logs",
name: LogsOverviewRoute.name,
TypedGoRoute<ConfigOptionsRoute>(
path: "/config-options",
name: ConfigOptionsRoute.name,
),
TypedGoRoute<SettingsRoute>(
path: "/settings",
name: SettingsRoute.name,
routes: [
TypedGoRoute<ConfigOptionsRoute>(
path: "config-options",
name: ConfigOptionsRoute.name,
),
TypedGoRoute<GeoAssetsRoute>(
path: "routing-assets",
name: GeoAssetsRoute.name,
),
],
),
TypedGoRoute<LogsOverviewRoute>(
path: "/logs",
name: LogsOverviewRoute.name,
),
TypedGoRoute<AboutRoute>(
path: "/about",
name: AboutRoute.name,
@@ -309,11 +309,7 @@ class ConfigOptionsRoute extends GoRouteData {
child: ConfigOptionsPage(),
);
}
return const MaterialPage(
fullscreenDialog: true,
name: name,
child: ConfigOptionsPage(),
);
return const NoTransitionPage(name: name, child: ConfigOptionsPage());
}
}