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

View File

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

View File

@@ -1,3 +1,4 @@
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';
import 'package:hiddify/core/localization/translations.dart'; import 'package:hiddify/core/localization/translations.dart';
@@ -25,23 +26,27 @@ class AdaptiveRootScaffold extends HookConsumerWidget {
final destinations = [ final destinations = [
NavigationDestination( NavigationDestination(
icon: const Icon(Icons.power_settings_new), icon: const Icon(FluentIcons.power_20_filled),
label: t.home.pageTitle, label: t.home.pageTitle,
), ),
NavigationDestination( NavigationDestination(
icon: const Icon(Icons.filter_list), icon: const Icon(FluentIcons.filter_20_filled),
label: t.proxies.pageTitle, label: t.proxies.pageTitle,
), ),
NavigationDestination( NavigationDestination(
icon: const Icon(Icons.article), icon: const Icon(FluentIcons.box_edit_20_filled),
label: t.logs.pageTitle, label: t.settings.config.pageTitle,
), ),
NavigationDestination( NavigationDestination(
icon: const Icon(Icons.settings), icon: const Icon(FluentIcons.settings_20_filled),
label: t.settings.pageTitle, label: t.settings.pageTitle,
), ),
NavigationDestination( 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, label: t.about.pageTitle,
), ),
]; ];

View File

@@ -6,6 +6,7 @@ import 'package:hiddify/core/localization/translations.dart';
import 'package:hiddify/core/model/failures.dart'; import 'package:hiddify/core/model/failures.dart';
import 'package:hiddify/core/model/range.dart'; import 'package:hiddify/core/model/range.dart';
import 'package:hiddify/core/widget/tip_card.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_entity.dart';
import 'package:hiddify/features/config_option/model/config_option_patch.dart'; import 'package:hiddify/features/config_option/model/config_option_patch.dart';
import 'package:hiddify/features/config_option/notifier/config_option_notifier.dart'; import 'package:hiddify/features/config_option/notifier/config_option_notifier.dart';
@@ -37,7 +38,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
} }
return Scaffold( return Scaffold(
appBar: AppBar( body: CustomScrollView(
slivers: [
NestedAppBar(
title: Text(t.settings.config.pageTitle), title: Text(t.settings.config.pageTitle),
actions: [ actions: [
if (asyncOptions case AsyncData(value: final options)) if (asyncOptions case AsyncData(value: final options))
@@ -65,8 +68,8 @@ class ConfigOptionsPage extends HookConsumerWidget {
), ),
], ],
), ),
body: switch (asyncOptions) { switch (asyncOptions) {
AsyncData(value: final options) => ListView( AsyncData(value: final options) => SliverList.list(
children: [ children: [
TipCard(message: t.settings.experimentalMsg), TipCard(message: t.settings.experimentalMsg),
ListTile( ListTile(
@@ -95,8 +98,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
SwitchListTile( SwitchListTile(
title: Text(t.settings.config.resolveDestination), title: Text(t.settings.config.resolveDestination),
value: options.resolveDestination, value: options.resolveDestination,
onChanged: (value) async => onChanged: (value) async => changeOption(
changeOption(ConfigOptionPatch(resolveDestination: value)), ConfigOptionPatch(resolveDestination: value),
),
), ),
ListTile( ListTile(
title: Text(t.settings.config.ipv6Mode), title: Text(t.settings.config.ipv6Mode),
@@ -125,7 +129,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
resetValue: defaultOptions.remoteDnsAddress, resetValue: defaultOptions.remoteDnsAddress,
).show(context); ).show(context);
if (url == null || url.isEmpty) return; if (url == null || url.isEmpty) return;
await changeOption(ConfigOptionPatch(remoteDnsAddress: url)); await changeOption(
ConfigOptionPatch(remoteDnsAddress: url),
);
}, },
), ),
ListTile( ListTile(
@@ -141,7 +147,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
).show(context); ).show(context);
if (domainStrategy == null) return; if (domainStrategy == null) return;
await changeOption( await changeOption(
ConfigOptionPatch(remoteDnsDomainStrategy: domainStrategy), ConfigOptionPatch(
remoteDnsDomainStrategy: domainStrategy,
),
); );
}, },
), ),
@@ -155,7 +163,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
resetValue: defaultOptions.directDnsAddress, resetValue: defaultOptions.directDnsAddress,
).show(context); ).show(context);
if (url == null || url.isEmpty) return; if (url == null || url.isEmpty) return;
await changeOption(ConfigOptionPatch(directDnsAddress: url)); await changeOption(
ConfigOptionPatch(directDnsAddress: url),
);
}, },
), ),
ListTile( ListTile(
@@ -171,7 +181,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
).show(context); ).show(context);
if (domainStrategy == null) return; if (domainStrategy == null) return;
await changeOption( await changeOption(
ConfigOptionPatch(directDnsDomainStrategy: domainStrategy), ConfigOptionPatch(
directDnsDomainStrategy: domainStrategy,
),
); );
}, },
), ),
@@ -280,7 +292,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
digitsOnly: true, digitsOnly: true,
).show(context); ).show(context);
if (mixedPort == null) return; if (mixedPort == null) return;
await changeOption(ConfigOptionPatch(mixedPort: mixedPort)); await changeOption(
ConfigOptionPatch(mixedPort: mixedPort),
);
}, },
), ),
ListTile( ListTile(
@@ -313,10 +327,12 @@ class ConfigOptionsPage extends HookConsumerWidget {
const SettingsDivider(), const SettingsDivider(),
SettingsSection(t.settings.config.section.tlsTricks), SettingsSection(t.settings.config.section.tlsTricks),
SwitchListTile( SwitchListTile(
title: Text(experimental(t.settings.config.enableTlsFragment)), title:
Text(experimental(t.settings.config.enableTlsFragment)),
value: options.enableTlsFragment, value: options.enableTlsFragment,
onChanged: (value) async => onChanged: (value) async => changeOption(
changeOption(ConfigOptionPatch(enableTlsFragment: value)), ConfigOptionPatch(enableTlsFragment: value),
),
), ),
ListTile( ListTile(
title: Text(t.settings.config.tlsFragmentSize), title: Text(t.settings.config.tlsFragmentSize),
@@ -330,7 +346,8 @@ class ConfigOptionsPage extends HookConsumerWidget {
if (range == null) return; if (range == null) return;
await changeOption( await changeOption(
ConfigOptionPatch( ConfigOptionPatch(
tlsFragmentSize: RangeWithOptionalCeil.tryParse(range), tlsFragmentSize:
RangeWithOptionalCeil.tryParse(range),
), ),
); );
}, },
@@ -347,21 +364,24 @@ class ConfigOptionsPage extends HookConsumerWidget {
if (range == null) return; if (range == null) return;
await changeOption( await changeOption(
ConfigOptionPatch( ConfigOptionPatch(
tlsFragmentSleep: RangeWithOptionalCeil.tryParse(range), tlsFragmentSleep:
RangeWithOptionalCeil.tryParse(range),
), ),
); );
}, },
), ),
SwitchListTile( SwitchListTile(
title: title: Text(
Text(experimental(t.settings.config.enableTlsMixedSniCase)), experimental(t.settings.config.enableTlsMixedSniCase),
),
value: options.enableTlsMixedSniCase, value: options.enableTlsMixedSniCase,
onChanged: (value) async => changeOption( onChanged: (value) async => changeOption(
ConfigOptionPatch(enableTlsMixedSniCase: value), ConfigOptionPatch(enableTlsMixedSniCase: value),
), ),
), ),
SwitchListTile( SwitchListTile(
title: Text(experimental(t.settings.config.enableTlsPadding)), title:
Text(experimental(t.settings.config.enableTlsPadding)),
value: options.enableTlsPadding, value: options.enableTlsPadding,
onChanged: (value) async => changeOption( onChanged: (value) async => changeOption(
ConfigOptionPatch(enableTlsPadding: value), ConfigOptionPatch(enableTlsPadding: value),
@@ -403,7 +423,9 @@ class ConfigOptionsPage extends HookConsumerWidget {
resetValue: defaultOptions.connectionTestUrl, resetValue: defaultOptions.connectionTestUrl,
).show(context); ).show(context);
if (url == null || url.isEmpty || !isUrl(url)) return; if (url == null || url.isEmpty || !isUrl(url)) return;
await changeOption(ConfigOptionPatch(connectionTestUrl: url)); await changeOption(
ConfigOptionPatch(connectionTestUrl: url),
);
}, },
), ),
ListTile( ListTile(
@@ -456,9 +478,10 @@ class ConfigOptionsPage extends HookConsumerWidget {
const Gap(24), const Gap(24),
], ],
), ),
AsyncError(:final error) => Center( AsyncError(:final error) => SliverFillRemaining(
child: SingleChildScrollView( hasScrollBody: false,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
const Icon(Icons.error), const Icon(Icons.error),
const Gap(2), const Gap(2),
@@ -475,9 +498,10 @@ class ConfigOptionsPage extends HookConsumerWidget {
], ],
), ),
), ),
), _ => const SliverToBoxAdapter(),
_ => const SizedBox(),
}, },
],
),
); );
} }
} }

View File

@@ -151,7 +151,7 @@ class _ConnectionButton extends StatelessWidget {
const Gap(16), const Gap(16),
Text( Text(
label, label,
style: Theme.of(context).textTheme.bodyLarge, style: Theme.of(context).textTheme.titleMedium,
), ),
], ],
); );

View File

@@ -23,13 +23,6 @@ class AdvancedSettingTiles extends HookConsumerWidget {
return Column( return Column(
children: [ children: [
const RegionPrefTile(), const RegionPrefTile(),
ListTile(
title: Text(t.settings.config.pageTitle),
leading: const Icon(Icons.edit_document),
onTap: () async {
await const ConfigOptionsRoute().push(context);
},
),
ListTile( ListTile(
title: Text(t.settings.geoAssets.pageTitle), title: Text(t.settings.geoAssets.pageTitle),
leading: const Icon(Icons.folder), leading: const Icon(Icons.folder),