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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';
|
||||
import 'package:hiddify/core/localization/translations.dart';
|
||||
@@ -25,23 +26,27 @@ class AdaptiveRootScaffold extends HookConsumerWidget {
|
||||
|
||||
final destinations = [
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.power_settings_new),
|
||||
icon: const Icon(FluentIcons.power_20_filled),
|
||||
label: t.home.pageTitle,
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.filter_list),
|
||||
icon: const Icon(FluentIcons.filter_20_filled),
|
||||
label: t.proxies.pageTitle,
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.article),
|
||||
label: t.logs.pageTitle,
|
||||
icon: const Icon(FluentIcons.box_edit_20_filled),
|
||||
label: t.settings.config.pageTitle,
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.settings),
|
||||
icon: const Icon(FluentIcons.settings_20_filled),
|
||||
label: t.settings.pageTitle,
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.info),
|
||||
icon: const Icon(FluentIcons.document_text_20_filled),
|
||||
label: t.logs.pageTitle,
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: const Icon(FluentIcons.info_20_filled),
|
||||
label: t.about.pageTitle,
|
||||
),
|
||||
];
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:hiddify/core/localization/translations.dart';
|
||||
import 'package:hiddify/core/model/failures.dart';
|
||||
import 'package:hiddify/core/model/range.dart';
|
||||
import 'package:hiddify/core/widget/tip_card.dart';
|
||||
import 'package:hiddify/features/common/nested_app_bar.dart';
|
||||
import 'package:hiddify/features/config_option/model/config_option_entity.dart';
|
||||
import 'package:hiddify/features/config_option/model/config_option_patch.dart';
|
||||
import 'package:hiddify/features/config_option/notifier/config_option_notifier.dart';
|
||||
@@ -37,7 +38,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
NestedAppBar(
|
||||
title: Text(t.settings.config.pageTitle),
|
||||
actions: [
|
||||
if (asyncOptions case AsyncData(value: final options))
|
||||
@@ -65,8 +68,8 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: switch (asyncOptions) {
|
||||
AsyncData(value: final options) => ListView(
|
||||
switch (asyncOptions) {
|
||||
AsyncData(value: final options) => SliverList.list(
|
||||
children: [
|
||||
TipCard(message: t.settings.experimentalMsg),
|
||||
ListTile(
|
||||
@@ -95,8 +98,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.config.resolveDestination),
|
||||
value: options.resolveDestination,
|
||||
onChanged: (value) async =>
|
||||
changeOption(ConfigOptionPatch(resolveDestination: value)),
|
||||
onChanged: (value) async => changeOption(
|
||||
ConfigOptionPatch(resolveDestination: value),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.ipv6Mode),
|
||||
@@ -125,7 +129,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
resetValue: defaultOptions.remoteDnsAddress,
|
||||
).show(context);
|
||||
if (url == null || url.isEmpty) return;
|
||||
await changeOption(ConfigOptionPatch(remoteDnsAddress: url));
|
||||
await changeOption(
|
||||
ConfigOptionPatch(remoteDnsAddress: url),
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
@@ -141,7 +147,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
).show(context);
|
||||
if (domainStrategy == null) return;
|
||||
await changeOption(
|
||||
ConfigOptionPatch(remoteDnsDomainStrategy: domainStrategy),
|
||||
ConfigOptionPatch(
|
||||
remoteDnsDomainStrategy: domainStrategy,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -155,7 +163,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
resetValue: defaultOptions.directDnsAddress,
|
||||
).show(context);
|
||||
if (url == null || url.isEmpty) return;
|
||||
await changeOption(ConfigOptionPatch(directDnsAddress: url));
|
||||
await changeOption(
|
||||
ConfigOptionPatch(directDnsAddress: url),
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
@@ -171,7 +181,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
).show(context);
|
||||
if (domainStrategy == null) return;
|
||||
await changeOption(
|
||||
ConfigOptionPatch(directDnsDomainStrategy: domainStrategy),
|
||||
ConfigOptionPatch(
|
||||
directDnsDomainStrategy: domainStrategy,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -280,7 +292,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
digitsOnly: true,
|
||||
).show(context);
|
||||
if (mixedPort == null) return;
|
||||
await changeOption(ConfigOptionPatch(mixedPort: mixedPort));
|
||||
await changeOption(
|
||||
ConfigOptionPatch(mixedPort: mixedPort),
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
@@ -313,10 +327,12 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
const SettingsDivider(),
|
||||
SettingsSection(t.settings.config.section.tlsTricks),
|
||||
SwitchListTile(
|
||||
title: Text(experimental(t.settings.config.enableTlsFragment)),
|
||||
title:
|
||||
Text(experimental(t.settings.config.enableTlsFragment)),
|
||||
value: options.enableTlsFragment,
|
||||
onChanged: (value) async =>
|
||||
changeOption(ConfigOptionPatch(enableTlsFragment: value)),
|
||||
onChanged: (value) async => changeOption(
|
||||
ConfigOptionPatch(enableTlsFragment: value),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.tlsFragmentSize),
|
||||
@@ -330,7 +346,8 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
if (range == null) return;
|
||||
await changeOption(
|
||||
ConfigOptionPatch(
|
||||
tlsFragmentSize: RangeWithOptionalCeil.tryParse(range),
|
||||
tlsFragmentSize:
|
||||
RangeWithOptionalCeil.tryParse(range),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -347,21 +364,24 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
if (range == null) return;
|
||||
await changeOption(
|
||||
ConfigOptionPatch(
|
||||
tlsFragmentSleep: RangeWithOptionalCeil.tryParse(range),
|
||||
tlsFragmentSleep:
|
||||
RangeWithOptionalCeil.tryParse(range),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title:
|
||||
Text(experimental(t.settings.config.enableTlsMixedSniCase)),
|
||||
title: Text(
|
||||
experimental(t.settings.config.enableTlsMixedSniCase),
|
||||
),
|
||||
value: options.enableTlsMixedSniCase,
|
||||
onChanged: (value) async => changeOption(
|
||||
ConfigOptionPatch(enableTlsMixedSniCase: value),
|
||||
),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: Text(experimental(t.settings.config.enableTlsPadding)),
|
||||
title:
|
||||
Text(experimental(t.settings.config.enableTlsPadding)),
|
||||
value: options.enableTlsPadding,
|
||||
onChanged: (value) async => changeOption(
|
||||
ConfigOptionPatch(enableTlsPadding: value),
|
||||
@@ -403,7 +423,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
resetValue: defaultOptions.connectionTestUrl,
|
||||
).show(context);
|
||||
if (url == null || url.isEmpty || !isUrl(url)) return;
|
||||
await changeOption(ConfigOptionPatch(connectionTestUrl: url));
|
||||
await changeOption(
|
||||
ConfigOptionPatch(connectionTestUrl: url),
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
@@ -456,9 +478,10 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
const Gap(24),
|
||||
],
|
||||
),
|
||||
AsyncError(:final error) => Center(
|
||||
child: SingleChildScrollView(
|
||||
AsyncError(:final error) => SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.error),
|
||||
const Gap(2),
|
||||
@@ -475,9 +498,10 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_ => const SizedBox(),
|
||||
_ => const SliverToBoxAdapter(),
|
||||
},
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ class _ConnectionButton extends StatelessWidget {
|
||||
const Gap(16),
|
||||
Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -23,13 +23,6 @@ class AdvancedSettingTiles extends HookConsumerWidget {
|
||||
return Column(
|
||||
children: [
|
||||
const RegionPrefTile(),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.pageTitle),
|
||||
leading: const Icon(Icons.edit_document),
|
||||
onTap: () async {
|
||||
await const ConfigOptionsRoute().push(context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.geoAssets.pageTitle),
|
||||
leading: const Icon(Icons.folder),
|
||||
|
||||
Reference in New Issue
Block a user