Change routing setup
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user