Add config options
This commit is contained in:
@@ -1,100 +0,0 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:hiddify/core/core_providers.dart';
|
||||
// import 'package:hiddify/core/prefs/prefs.dart';
|
||||
// import 'package:hiddify/domain/clash/clash.dart';
|
||||
// import 'package:hiddify/features/settings/widgets/widgets.dart';
|
||||
// import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
// import 'package:recase/recase.dart';
|
||||
|
||||
// class ClashOverridesPage extends HookConsumerWidget {
|
||||
// const ClashOverridesPage({super.key});
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context, WidgetRef ref) {
|
||||
// final t = ref.watch(translationsProvider);
|
||||
|
||||
// final overrides =
|
||||
// ref.watch(prefsControllerProvider.select((value) => value.clash));
|
||||
// final notifier = ref.watch(prefsControllerProvider.notifier);
|
||||
|
||||
// return Scaffold(
|
||||
// body: CustomScrollView(
|
||||
// slivers: [
|
||||
// SliverAppBar(
|
||||
// title: Text(t.settings.clash.sectionTitle.titleCase),
|
||||
// pinned: true,
|
||||
// ),
|
||||
// SliverList.list(
|
||||
// children: [
|
||||
// InputOverrideTile(
|
||||
// title: t.settings.clash.overrides.httpPort,
|
||||
// value: overrides.httpPort,
|
||||
// onChange: (value) => notifier.patchClashOverrides(
|
||||
// ClashConfigPatch(httpPort: value),
|
||||
// ),
|
||||
// ),
|
||||
// InputOverrideTile(
|
||||
// title: t.settings.clash.overrides.socksPort,
|
||||
// value: overrides.socksPort,
|
||||
// onChange: (value) => notifier.patchClashOverrides(
|
||||
// ClashConfigPatch(socksPort: value),
|
||||
// ),
|
||||
// ),
|
||||
// InputOverrideTile(
|
||||
// title: t.settings.clash.overrides.redirPort,
|
||||
// value: overrides.redirPort,
|
||||
// onChange: (value) => notifier.patchClashOverrides(
|
||||
// ClashConfigPatch(redirPort: value),
|
||||
// ),
|
||||
// ),
|
||||
// InputOverrideTile(
|
||||
// title: t.settings.clash.overrides.tproxyPort,
|
||||
// value: overrides.tproxyPort,
|
||||
// onChange: (value) => notifier.patchClashOverrides(
|
||||
// ClashConfigPatch(tproxyPort: value),
|
||||
// ),
|
||||
// ),
|
||||
// InputOverrideTile(
|
||||
// title: t.settings.clash.overrides.mixedPort,
|
||||
// value: overrides.mixedPort,
|
||||
// onChange: (value) => notifier.patchClashOverrides(
|
||||
// ClashConfigPatch(mixedPort: value),
|
||||
// ),
|
||||
// ),
|
||||
// ToggleOverrideTile(
|
||||
// title: t.settings.clash.overrides.allowLan,
|
||||
// value: overrides.allowLan,
|
||||
// onChange: (value) => notifier.patchClashOverrides(
|
||||
// ClashConfigPatch(allowLan: value),
|
||||
// ),
|
||||
// ),
|
||||
// ToggleOverrideTile(
|
||||
// title: t.settings.clash.overrides.ipv6,
|
||||
// value: overrides.ipv6,
|
||||
// onChange: (value) => notifier.patchClashOverrides(
|
||||
// ClashConfigPatch(ipv6: value),
|
||||
// ),
|
||||
// ),
|
||||
// ChoiceOverrideTile(
|
||||
// title: t.settings.clash.overrides.mode,
|
||||
// value: overrides.mode,
|
||||
// options: TunnelMode.values,
|
||||
// onChange: (value) => notifier.patchClashOverrides(
|
||||
// ClashConfigPatch(mode: value),
|
||||
// ),
|
||||
// ),
|
||||
// ChoiceOverrideTile(
|
||||
// title: t.settings.clash.overrides.logLevel,
|
||||
// value: overrides.logLevel,
|
||||
// options: LogLevel.values,
|
||||
// onChange: (value) => notifier.patchClashOverrides(
|
||||
// ClashConfigPatch(logLevel: value),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
214
lib/features/settings/view/config_options_page.dart
Normal file
214
lib/features/settings/view/config_options_page.dart
Normal file
@@ -0,0 +1,214 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:hiddify/core/core_providers.dart';
|
||||
import 'package:hiddify/core/prefs/prefs.dart';
|
||||
import 'package:hiddify/data/repository/config_options_store.dart';
|
||||
import 'package:hiddify/domain/singbox/singbox.dart';
|
||||
import 'package:hiddify/features/settings/widgets/widgets.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
class ConfigOptionsPage extends HookConsumerWidget {
|
||||
const ConfigOptionsPage({super.key});
|
||||
|
||||
static final _default = ConfigOptions.initial;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final t = ref.watch(translationsProvider);
|
||||
|
||||
final options = ref.watch(configOptionsProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(t.settings.config.pageTitle),
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
if (ref.watch(debugModeProvider))
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.config.executeConfigAsIs),
|
||||
subtitle: Text(t.settings.config.executeConfigAsIsMsg),
|
||||
value: options.executeConfigAsIs,
|
||||
onChanged: ref.read(executeConfigAsIs.notifier).update,
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.logLevel),
|
||||
subtitle: Text(options.logLevel.name),
|
||||
onTap: () async {
|
||||
final logLevel = await SettingsPickerDialog(
|
||||
title: t.settings.config.logLevel,
|
||||
selected: options.logLevel,
|
||||
options: LogLevel.values,
|
||||
getTitle: (e) => e.name,
|
||||
resetValue: _default.logLevel,
|
||||
).show(context);
|
||||
if (logLevel == null) return;
|
||||
await ref.read(logLevelStore.notifier).update(logLevel);
|
||||
},
|
||||
),
|
||||
const SettingsDivider(),
|
||||
SettingsSection(t.settings.config.section.route),
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.config.resolveDestination),
|
||||
value: options.resolveDestination,
|
||||
onChanged: ref.read(resolveDestinationStore.notifier).update,
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.ipv6Mode),
|
||||
subtitle: Text(options.ipv6Mode.present(t)),
|
||||
onTap: () async {
|
||||
final ipv6Mode = await SettingsPickerDialog(
|
||||
title: t.settings.config.ipv6Mode,
|
||||
selected: options.ipv6Mode,
|
||||
options: IPv6Mode.values,
|
||||
getTitle: (e) => e.present(t),
|
||||
resetValue: _default.ipv6Mode,
|
||||
).show(context);
|
||||
if (ipv6Mode == null) return;
|
||||
await ref.read(ipv6ModeStore.notifier).update(ipv6Mode);
|
||||
},
|
||||
),
|
||||
const SettingsDivider(),
|
||||
SettingsSection(t.settings.config.section.dns),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.remoteDnsAddress),
|
||||
subtitle: Text(options.remoteDnsAddress),
|
||||
onTap: () async {
|
||||
final url = await SettingsInputDialog(
|
||||
title: t.settings.config.remoteDnsAddress,
|
||||
initialValue: options.remoteDnsAddress,
|
||||
resetValue: _default.remoteDnsAddress,
|
||||
).show(context);
|
||||
if (url == null || url.isEmpty) return;
|
||||
await ref.read(remoteDnsAddressStore.notifier).update(url);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.remoteDnsDomainStrategy),
|
||||
subtitle: Text(options.remoteDnsDomainStrategy.displayName),
|
||||
onTap: () async {
|
||||
final domainStrategy = await SettingsPickerDialog(
|
||||
title: t.settings.config.remoteDnsDomainStrategy,
|
||||
selected: options.remoteDnsDomainStrategy,
|
||||
options: DomainStrategy.values,
|
||||
getTitle: (e) => e.displayName,
|
||||
resetValue: _default.remoteDnsDomainStrategy,
|
||||
).show(context);
|
||||
if (domainStrategy == null) return;
|
||||
await ref
|
||||
.read(remoteDnsDomainStrategyStore.notifier)
|
||||
.update(domainStrategy);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.directDnsAddress),
|
||||
subtitle: Text(options.directDnsAddress),
|
||||
onTap: () async {
|
||||
final url = await SettingsInputDialog(
|
||||
title: t.settings.config.directDnsAddress,
|
||||
initialValue: options.directDnsAddress,
|
||||
resetValue: _default.directDnsAddress,
|
||||
).show(context);
|
||||
if (url == null || url.isEmpty) return;
|
||||
await ref.read(directDnsAddressStore.notifier).update(url);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.directDnsDomainStrategy),
|
||||
subtitle: Text(options.directDnsDomainStrategy.displayName),
|
||||
onTap: () async {
|
||||
final domainStrategy = await SettingsPickerDialog(
|
||||
title: t.settings.config.directDnsDomainStrategy,
|
||||
selected: options.directDnsDomainStrategy,
|
||||
options: DomainStrategy.values,
|
||||
getTitle: (e) => e.displayName,
|
||||
resetValue: _default.directDnsDomainStrategy,
|
||||
).show(context);
|
||||
if (domainStrategy == null) return;
|
||||
await ref
|
||||
.read(directDnsDomainStrategyStore.notifier)
|
||||
.update(domainStrategy);
|
||||
},
|
||||
),
|
||||
const SettingsDivider(),
|
||||
SettingsSection(t.settings.config.section.inbound),
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.config.enableTun),
|
||||
value: options.enableTun,
|
||||
onChanged: ref.read(enableTunStore.notifier).update,
|
||||
),
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.config.setSystemProxy),
|
||||
value: options.setSystemProxy,
|
||||
onChanged: ref.read(setSystemProxyStore.notifier).update,
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.mixedPort),
|
||||
subtitle: Text(options.mixedPort.toString()),
|
||||
onTap: () async {
|
||||
final mixedPort = await SettingsInputDialog(
|
||||
title: t.settings.config.mixedPort,
|
||||
initialValue: options.mixedPort,
|
||||
resetValue: _default.mixedPort,
|
||||
validator: isPort,
|
||||
mapTo: int.tryParse,
|
||||
digitsOnly: true,
|
||||
).show(context);
|
||||
if (mixedPort == null) return;
|
||||
await ref.read(mixedPortStore.notifier).update(mixedPort);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.localDnsPort),
|
||||
subtitle: Text(options.localDnsPort.toString()),
|
||||
onTap: () async {
|
||||
final localDnsPort = await SettingsInputDialog(
|
||||
title: t.settings.config.localDnsPort,
|
||||
initialValue: options.localDnsPort,
|
||||
resetValue: _default.localDnsPort,
|
||||
validator: isPort,
|
||||
mapTo: int.tryParse,
|
||||
digitsOnly: true,
|
||||
).show(context);
|
||||
if (localDnsPort == null) return;
|
||||
await ref.read(localDnsPortStore.notifier).update(localDnsPort);
|
||||
},
|
||||
),
|
||||
const SettingsDivider(),
|
||||
SettingsSection(t.settings.config.section.misc),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.connectionTestUrl),
|
||||
subtitle: Text(options.connectionTestUrl),
|
||||
onTap: () async {
|
||||
final url = await SettingsInputDialog(
|
||||
title: t.settings.config.connectionTestUrl,
|
||||
initialValue: options.connectionTestUrl,
|
||||
resetValue: _default.connectionTestUrl,
|
||||
).show(context);
|
||||
if (url == null || url.isEmpty || !isUrl(url)) return;
|
||||
await ref.read(connectionTestUrlStore.notifier).update(url);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.clashApiPort),
|
||||
subtitle: Text(options.clashApiPort.toString()),
|
||||
onTap: () async {
|
||||
final clashApiPort = await SettingsInputDialog(
|
||||
title: t.settings.config.clashApiPort,
|
||||
initialValue: options.clashApiPort,
|
||||
resetValue: _default.clashApiPort,
|
||||
validator: isPort,
|
||||
mapTo: int.tryParse,
|
||||
digitsOnly: true,
|
||||
).show(context);
|
||||
if (clashApiPort == null) return;
|
||||
await ref.read(clashApiPortStore.notifier).update(clashApiPort);
|
||||
},
|
||||
),
|
||||
const Gap(24),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:hiddify/core/core_providers.dart';
|
||||
import 'package:hiddify/features/settings/widgets/miscellaneous_setting_tiles.dart';
|
||||
import 'package:hiddify/features/settings/widgets/widgets.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:recase/recase.dart';
|
||||
|
||||
class SettingsPage extends HookConsumerWidget {
|
||||
const SettingsPage({super.key});
|
||||
@@ -13,58 +11,19 @@ class SettingsPage extends HookConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final t = ref.watch(translationsProvider);
|
||||
|
||||
// const divider = Divider(indent: 16, endIndent: 16);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(t.settings.pageTitle.titleCase),
|
||||
title: Text(t.settings.pageTitle),
|
||||
),
|
||||
body: ListTileTheme(
|
||||
data: ListTileTheme.of(context).copyWith(
|
||||
contentPadding: const EdgeInsetsDirectional.only(start: 48, end: 16),
|
||||
),
|
||||
child: ListView(
|
||||
children: [
|
||||
_SettingsSectionHeader(
|
||||
t.settings.general.sectionTitle.titleCase,
|
||||
),
|
||||
const AppearanceSettingTiles(),
|
||||
// divider,
|
||||
// _SettingsSectionHeader(t.settings.network.sectionTitle.titleCase),
|
||||
// const NetworkSettingTiles(),
|
||||
// divider,
|
||||
// ListTile(
|
||||
// title: Text(t.settings.clash.sectionTitle.titleCase),
|
||||
// leading: const Icon(Icons.edit_document),
|
||||
// contentPadding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
// onTap: () async {
|
||||
// await const ClashOverridesRoute().push(context);
|
||||
// },
|
||||
// ),
|
||||
_SettingsSectionHeader(
|
||||
t.settings.miscellaneous.sectionTitle.titleCase,
|
||||
),
|
||||
const MiscellaneousSettingTiles(),
|
||||
const Gap(16),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SettingsSectionHeader extends StatelessWidget {
|
||||
const _SettingsSectionHeader(this.title);
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
body: ListView(
|
||||
children: [
|
||||
SettingsSection(t.settings.general.sectionTitle),
|
||||
const GeneralSettingTiles(),
|
||||
const SettingsDivider(),
|
||||
SettingsSection(t.settings.advanced.sectionTitle),
|
||||
const AdvancedSettingTiles(),
|
||||
const Gap(16),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export 'clash_overrides_page.dart';
|
||||
export 'config_options_page.dart';
|
||||
export 'settings_page.dart';
|
||||
|
||||
56
lib/features/settings/widgets/advanced_setting_tiles.dart
Normal file
56
lib/features/settings/widgets/advanced_setting_tiles.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hiddify/core/core_providers.dart';
|
||||
import 'package:hiddify/core/prefs/prefs.dart';
|
||||
import 'package:hiddify/core/router/routes/routes.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
class AdvancedSettingTiles extends HookConsumerWidget {
|
||||
const AdvancedSettingTiles({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final t = ref.watch(translationsProvider);
|
||||
|
||||
final debug = ref.watch(debugModeProvider);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(t.settings.config.pageTitle),
|
||||
leading: const Icon(Icons.edit_document),
|
||||
onTap: () async {
|
||||
await const ConfigOptionsRoute().push(context);
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.advanced.debugMode),
|
||||
value: debug,
|
||||
secondary: const Icon(Icons.bug_report),
|
||||
onChanged: (value) async {
|
||||
if (value) {
|
||||
await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(t.settings.advanced.debugMode),
|
||||
content: Text(t.settings.advanced.debugModeMsg),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(true),
|
||||
child: Text(
|
||||
MaterialLocalizations.of(context).okButtonLabel,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
await ref.read(debugModeProvider.notifier).update(value);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,11 @@ import 'package:hiddify/core/locale/locale.dart';
|
||||
import 'package:hiddify/core/prefs/general_prefs.dart';
|
||||
import 'package:hiddify/core/theme/theme.dart';
|
||||
import 'package:hiddify/features/settings/widgets/theme_mode_switch_button.dart';
|
||||
import 'package:hiddify/services/service_providers.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:recase/recase.dart';
|
||||
|
||||
class AppearanceSettingTiles extends HookConsumerWidget {
|
||||
const AppearanceSettingTiles({super.key});
|
||||
class GeneralSettingTiles extends HookConsumerWidget {
|
||||
const GeneralSettingTiles({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
@@ -26,17 +24,18 @@ class AppearanceSettingTiles extends HookConsumerWidget {
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(t.settings.general.locale.titleCase),
|
||||
title: Text(t.settings.general.locale),
|
||||
subtitle: Text(
|
||||
LocaleNamesLocalizationsDelegate.nativeLocaleNames[locale.name] ??
|
||||
locale.name,
|
||||
),
|
||||
leading: const Icon(Icons.language),
|
||||
onTap: () async {
|
||||
final selectedLocale = await showDialog<LocalePref>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return SimpleDialog(
|
||||
title: Text(t.settings.general.locale.titleCase),
|
||||
title: Text(t.settings.general.locale),
|
||||
children: LocalePref.values
|
||||
.map(
|
||||
(e) => RadioListTile(
|
||||
@@ -62,14 +61,13 @@ class AppearanceSettingTiles extends HookConsumerWidget {
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.general.themeMode.titleCase),
|
||||
title: Text(t.settings.general.themeMode),
|
||||
subtitle: Text(
|
||||
switch (theme.themeMode) {
|
||||
ThemeMode.system => t.settings.general.themeModes.system,
|
||||
ThemeMode.light => t.settings.general.themeModes.light,
|
||||
ThemeMode.dark => t.settings.general.themeModes.dark,
|
||||
}
|
||||
.sentenceCase,
|
||||
},
|
||||
),
|
||||
trailing: ThemeModeSwitch(
|
||||
themeMode: theme.themeMode,
|
||||
@@ -77,6 +75,7 @@ class AppearanceSettingTiles extends HookConsumerWidget {
|
||||
themeController.change(themeMode: value);
|
||||
},
|
||||
),
|
||||
leading: const Icon(Icons.light_mode),
|
||||
onTap: () async {
|
||||
await themeController.change(
|
||||
themeMode: Theme.of(context).brightness == Brightness.light
|
||||
@@ -86,7 +85,7 @@ class AppearanceSettingTiles extends HookConsumerWidget {
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.general.trueBlack.titleCase),
|
||||
title: Text(t.settings.general.trueBlack),
|
||||
value: theme.trueBlack,
|
||||
onChanged: (value) {
|
||||
themeController.change(trueBlack: value);
|
||||
@@ -94,20 +93,12 @@ class AppearanceSettingTiles extends HookConsumerWidget {
|
||||
),
|
||||
if (PlatformUtils.isDesktop) ...[
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.general.silentStart.titleCase),
|
||||
title: Text(t.settings.general.silentStart),
|
||||
value: ref.watch(silentStartProvider),
|
||||
onChanged: (value) async {
|
||||
await ref.read(silentStartProvider.notifier).update(value);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(t.settings.general.openWorkingDir.titleCase),
|
||||
trailing: const Icon(Icons.arrow_outward_outlined),
|
||||
onTap: () async {
|
||||
final path = ref.read(filesEditorServiceProvider).workingDir.uri;
|
||||
await UriUtils.tryLaunch(path);
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hiddify/core/core_providers.dart';
|
||||
import 'package:hiddify/core/prefs/misc_prefs.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:recase/recase.dart';
|
||||
|
||||
class MiscellaneousSettingTiles extends HookConsumerWidget {
|
||||
const MiscellaneousSettingTiles({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final t = ref.watch(translationsProvider);
|
||||
|
||||
// final connectionTestUrl = ref.watch(connectionTestUrlProvider);
|
||||
// final concurrentTestCount = ref.watch(concurrentTestCountProvider);
|
||||
final debug = ref.watch(debugModeProvider);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// ListTile(
|
||||
// title: Text(t.settings.miscellaneous.connectionTestUrl.titleCase),
|
||||
// subtitle: Text(connectionTestUrl),
|
||||
// onTap: () async {
|
||||
// final url = await SettingsInputDialog<String>(
|
||||
// title: t.settings.miscellaneous.connectionTestUrl.titleCase,
|
||||
// initialValue: connectionTestUrl,
|
||||
// resetValue: Defaults.connectionTestUrl,
|
||||
// ).show(context);
|
||||
// if (url == null || url.isEmpty || !isUrl(url)) return;
|
||||
// await ref.read(connectionTestUrlProvider.notifier).update(url);
|
||||
// },
|
||||
// ),
|
||||
// ListTile(
|
||||
// title: Text(t.settings.miscellaneous.concurrentTestCount.titleCase),
|
||||
// trailing: Text(concurrentTestCount.toString()),
|
||||
// leadingAndTrailingTextStyle: Theme.of(context).textTheme.bodyMedium,
|
||||
// onTap: () async {
|
||||
// final val = await SettingsInputDialog<int>(
|
||||
// title: t.settings.miscellaneous.concurrentTestCount.titleCase,
|
||||
// initialValue: concurrentTestCount,
|
||||
// resetValue: Defaults.concurrentTestCount,
|
||||
// mapTo: (value) => int.tryParse(value),
|
||||
// digitsOnly: true,
|
||||
// ).show(context);
|
||||
// if (val == null || val < 1) return;
|
||||
// await ref.read(concurrentTestCountProvider.notifier).update(val);
|
||||
// },
|
||||
// ),
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.miscellaneous.debugMode.titleCase),
|
||||
value: debug,
|
||||
onChanged: (value) async {
|
||||
if (value) {
|
||||
await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(t.settings.miscellaneous.debugMode.titleCase),
|
||||
content: Text(
|
||||
t.settings.miscellaneous.debugModeMsg.sentenceCase,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(true),
|
||||
child: Text(
|
||||
MaterialLocalizations.of(context).okButtonLabel,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
await ref.read(debugModeProvider.notifier).update(value);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:hiddify/core/core_providers.dart';
|
||||
// import 'package:hiddify/core/prefs/prefs.dart';
|
||||
// import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
// import 'package:recase/recase.dart';
|
||||
|
||||
// class NetworkSettingTiles extends HookConsumerWidget {
|
||||
// const NetworkSettingTiles({super.key});
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context, WidgetRef ref) {
|
||||
// final t = ref.watch(translationsProvider);
|
||||
|
||||
// final prefs =
|
||||
// ref.watch(prefsControllerProvider.select((value) => value.network));
|
||||
// final notifier = ref.watch(prefsControllerProvider.notifier);
|
||||
|
||||
// return Column(
|
||||
// children: [
|
||||
// SwitchListTile(
|
||||
// title: Text(t.settings.network.systemProxy.titleCase),
|
||||
// subtitle: Text(t.settings.network.systemProxyMsg),
|
||||
// value: prefs.systemProxy,
|
||||
// onChanged: (value) => notifier.patchNetworkPrefs(systemProxy: value),
|
||||
// ),
|
||||
// SwitchListTile(
|
||||
// title: Text(t.settings.network.bypassPrivateNetworks.titleCase),
|
||||
// subtitle: Text(t.settings.network.bypassPrivateNetworksMsg),
|
||||
// value: prefs.bypassPrivateNetworks,
|
||||
// onChanged: (value) =>
|
||||
// notifier.patchNetworkPrefs(bypassPrivateNetworks: value),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
@@ -1,153 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:hiddify/core/core_providers.dart';
|
||||
import 'package:hiddify/features/settings/widgets/settings_input_dialog.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:recase/recase.dart';
|
||||
|
||||
class InputOverrideTile extends HookConsumerWidget {
|
||||
const InputOverrideTile({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.value,
|
||||
this.resetValue,
|
||||
required this.onChange,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final int? value;
|
||||
final int? resetValue;
|
||||
final ValueChanged<Option<int>> onChange;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final t = ref.watch(translationsProvider);
|
||||
|
||||
return ListTile(
|
||||
title: Text(title),
|
||||
leadingAndTrailingTextStyle: Theme.of(context).textTheme.bodyMedium,
|
||||
trailing: Text(
|
||||
value == null
|
||||
? t.settings.clash.doNotModify.sentenceCase
|
||||
: value.toString(),
|
||||
),
|
||||
onTap: () async {
|
||||
final result = await OptionalSettingsInputDialog<int>(
|
||||
title: title,
|
||||
initialValue: value,
|
||||
resetValue: optionOf(resetValue),
|
||||
).show(context).then(
|
||||
(value) {
|
||||
return value?.match<Option<int>?>(
|
||||
() => none(),
|
||||
(t) {
|
||||
final i = int.tryParse(t);
|
||||
return i == null ? null : some(i);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
if (result == null) return;
|
||||
onChange(result);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ToggleOverrideTile extends HookConsumerWidget {
|
||||
const ToggleOverrideTile({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.value,
|
||||
required this.onChange,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final bool? value;
|
||||
final ValueChanged<Option<bool>> onChange;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final t = ref.watch(translationsProvider);
|
||||
|
||||
return PopupMenuButton<Option<bool>>(
|
||||
initialValue: optionOf(value),
|
||||
onSelected: onChange,
|
||||
child: ListTile(
|
||||
title: Text(title),
|
||||
leadingAndTrailingTextStyle: Theme.of(context).textTheme.bodyMedium,
|
||||
trailing: Text(
|
||||
(value == null
|
||||
? t.settings.clash.doNotModify
|
||||
: value!
|
||||
? t.general.toggle.enabled
|
||||
: t.general.toggle.disabled)
|
||||
.sentenceCase,
|
||||
),
|
||||
),
|
||||
itemBuilder: (_) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
value: none(),
|
||||
child: Text(t.settings.clash.doNotModify.sentenceCase),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: some(true),
|
||||
child: Text(t.general.toggle.enabled.sentenceCase),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: some(false),
|
||||
child: Text(t.general.toggle.disabled.sentenceCase),
|
||||
),
|
||||
];
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ChoiceOverrideTile<T extends Enum> extends HookConsumerWidget {
|
||||
const ChoiceOverrideTile({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.value,
|
||||
required this.options,
|
||||
required this.onChange,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final T? value;
|
||||
final List<T> options;
|
||||
final ValueChanged<Option<T>> onChange;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final t = ref.watch(translationsProvider);
|
||||
|
||||
return PopupMenuButton<Option<T>>(
|
||||
initialValue: optionOf(value),
|
||||
onSelected: onChange,
|
||||
child: ListTile(
|
||||
title: Text(title),
|
||||
leadingAndTrailingTextStyle: Theme.of(context).textTheme.bodyMedium,
|
||||
trailing: Text(
|
||||
(value == null ? t.settings.clash.doNotModify : value!.name)
|
||||
.sentenceCase,
|
||||
),
|
||||
),
|
||||
itemBuilder: (_) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
value: none(),
|
||||
child: Text(t.settings.clash.doNotModify.sentenceCase),
|
||||
),
|
||||
...options.map(
|
||||
(e) => PopupMenuItem(
|
||||
value: some(e),
|
||||
child: Text(e.name.sentenceCase),
|
||||
),
|
||||
),
|
||||
];
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
25
lib/features/settings/widgets/sections_widgets.dart
Normal file
25
lib/features/settings/widgets/sections_widgets.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SettingsSection extends StatelessWidget {
|
||||
const SettingsSection(this.title, {super.key});
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
title: Text(title),
|
||||
titleTextStyle: Theme.of(context).textTheme.titleSmall,
|
||||
dense: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsDivider extends StatelessWidget {
|
||||
const SettingsDivider({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Divider(indent: 16, endIndent: 16);
|
||||
}
|
||||
}
|
||||
@@ -1,88 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hiddify/core/core_providers.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
class OptionalSettingsInputDialog<T> extends HookConsumerWidget
|
||||
with PresLogger {
|
||||
const OptionalSettingsInputDialog({
|
||||
super.key,
|
||||
required this.title,
|
||||
this.initialValue,
|
||||
this.resetValue = const None(),
|
||||
this.icon,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final T? initialValue;
|
||||
|
||||
/// default value, useful for mandatory fields
|
||||
final Option<T> resetValue;
|
||||
final IconData? icon;
|
||||
|
||||
Future<Option<String>?> show(BuildContext context) async {
|
||||
return showDialog(
|
||||
context: context,
|
||||
useRootNavigator: true,
|
||||
builder: (context) => this,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final t = ref.watch(translationsProvider);
|
||||
final localizations = MaterialLocalizations.of(context);
|
||||
|
||||
final textController = useTextEditingController(
|
||||
text: initialValue?.toString(),
|
||||
);
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
icon: icon != null ? Icon(icon) : null,
|
||||
content: TextFormField(
|
||||
controller: textController,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.singleLineFormatter,
|
||||
],
|
||||
autovalidateMode: AutovalidateMode.always,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await Navigator.of(context)
|
||||
.maybePop(resetValue.map((t) => t.toString()));
|
||||
},
|
||||
child: Text(t.general.reset.toUpperCase()),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).maybePop();
|
||||
},
|
||||
child: Text(localizations.cancelButtonLabel.toUpperCase()),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
// onConfirm(textController.value.text);
|
||||
await Navigator.of(context)
|
||||
.maybePop(some(textController.value.text));
|
||||
},
|
||||
child: Text(localizations.okButtonLabel.toUpperCase()),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsInputDialog<T> extends HookConsumerWidget with PresLogger {
|
||||
const SettingsInputDialog({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.initialValue,
|
||||
this.mapTo,
|
||||
this.validator,
|
||||
this.resetValue,
|
||||
this.icon,
|
||||
this.digitsOnly = false,
|
||||
@@ -91,6 +21,7 @@ class SettingsInputDialog<T> extends HookConsumerWidget with PresLogger {
|
||||
final String title;
|
||||
final T initialValue;
|
||||
final T? Function(String value)? mapTo;
|
||||
final bool Function(String value)? validator;
|
||||
final T? resetValue;
|
||||
final IconData? icon;
|
||||
final bool digitsOnly;
|
||||
@@ -139,7 +70,9 @@ class SettingsInputDialog<T> extends HookConsumerWidget with PresLogger {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
if (mapTo != null) {
|
||||
if (validator?.call(textController.value.text) == false) {
|
||||
await Navigator.of(context).maybePop(null);
|
||||
} else if (mapTo != null) {
|
||||
await Navigator.of(context)
|
||||
.maybePop(mapTo!.call(textController.value.text));
|
||||
} else {
|
||||
@@ -153,3 +86,66 @@ class SettingsInputDialog<T> extends HookConsumerWidget with PresLogger {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsPickerDialog<T> extends HookConsumerWidget with PresLogger {
|
||||
const SettingsPickerDialog({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.selected,
|
||||
required this.options,
|
||||
required this.getTitle,
|
||||
this.resetValue,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final T selected;
|
||||
final List<T> options;
|
||||
final String Function(T e) getTitle;
|
||||
final T? resetValue;
|
||||
|
||||
Future<T?> show(BuildContext context) async {
|
||||
return showDialog(
|
||||
context: context,
|
||||
useRootNavigator: true,
|
||||
builder: (context) => this,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final t = ref.watch(translationsProvider);
|
||||
final localizations = MaterialLocalizations.of(context);
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
content: Column(
|
||||
children: options
|
||||
.map(
|
||||
(e) => RadioListTile(
|
||||
title: Text(getTitle(e)),
|
||||
value: e,
|
||||
groupValue: selected,
|
||||
onChanged: (value) => context.pop(e),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
actions: [
|
||||
if (resetValue != null)
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).maybePop(resetValue);
|
||||
},
|
||||
child: Text(t.general.reset.toUpperCase()),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).maybePop();
|
||||
},
|
||||
child: Text(localizations.cancelButtonLabel.toUpperCase()),
|
||||
),
|
||||
],
|
||||
scrollable: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export 'advanced_setting_tiles.dart';
|
||||
export 'general_setting_tiles.dart';
|
||||
export 'network_setting_tiles.dart';
|
||||
export 'override_tiles.dart';
|
||||
export 'sections_widgets.dart';
|
||||
export 'settings_input_dialog.dart';
|
||||
|
||||
Reference in New Issue
Block a user