Refactor preferences
This commit is contained in:
@@ -18,8 +18,8 @@ class AdvancedSettingTiles extends HookConsumerWidget {
|
||||
final t = ref.watch(translationsProvider);
|
||||
|
||||
final debug = ref.watch(debugModeNotifierProvider);
|
||||
final perAppProxy = ref.watch(perAppProxyModeNotifierProvider).enabled;
|
||||
final disableMemoryLimit = ref.watch(disableMemoryLimitProvider);
|
||||
final perAppProxy = ref.watch(Preferences.perAppProxyMode).enabled;
|
||||
final disableMemoryLimit = ref.watch(Preferences.disableMemoryLimit);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
@@ -43,7 +43,7 @@ class AdvancedSettingTiles extends HookConsumerWidget {
|
||||
final newMode =
|
||||
perAppProxy ? PerAppProxyMode.off : PerAppProxyMode.exclude;
|
||||
await ref
|
||||
.read(perAppProxyModeNotifierProvider.notifier)
|
||||
.read(Preferences.perAppProxyMode.notifier)
|
||||
.update(newMode);
|
||||
if (!perAppProxy && context.mounted) {
|
||||
await const PerAppProxyRoute().push(context);
|
||||
@@ -53,7 +53,7 @@ class AdvancedSettingTiles extends HookConsumerWidget {
|
||||
onTap: () async {
|
||||
if (!perAppProxy) {
|
||||
await ref
|
||||
.read(perAppProxyModeNotifierProvider.notifier)
|
||||
.read(Preferences.perAppProxyMode.notifier)
|
||||
.update(PerAppProxyMode.exclude);
|
||||
}
|
||||
if (context.mounted) await const PerAppProxyRoute().push(context);
|
||||
@@ -66,7 +66,9 @@ class AdvancedSettingTiles extends HookConsumerWidget {
|
||||
value: !disableMemoryLimit,
|
||||
secondary: const Icon(FluentIcons.developer_board_24_regular),
|
||||
onChanged: (value) async {
|
||||
await ref.read(disableMemoryLimitProvider.notifier).update(!value);
|
||||
await ref
|
||||
.read(Preferences.disableMemoryLimit.notifier)
|
||||
.update(!value);
|
||||
},
|
||||
),
|
||||
if (Platform.isIOS)
|
||||
|
||||
@@ -58,17 +58,17 @@ class GeneralSettingTiles extends HookConsumerWidget {
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.general.autoIpCheck),
|
||||
secondary: const Icon(FluentIcons.globe_search_24_regular),
|
||||
value: ref.watch(autoCheckIpProvider),
|
||||
onChanged: ref.read(autoCheckIpProvider.notifier).update,
|
||||
value: ref.watch(Preferences.autoCheckIp),
|
||||
onChanged: ref.read(Preferences.autoCheckIp.notifier).update,
|
||||
),
|
||||
if (Platform.isAndroid) ...[
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.general.dynamicNotification),
|
||||
secondary: const Icon(FluentIcons.top_speed_24_regular),
|
||||
value: ref.watch(dynamicNotificationProvider),
|
||||
value: ref.watch(Preferences.dynamicNotification),
|
||||
onChanged: (value) async {
|
||||
await ref
|
||||
.read(dynamicNotificationProvider.notifier)
|
||||
.read(Preferences.dynamicNotification.notifier)
|
||||
.update(value);
|
||||
},
|
||||
),
|
||||
@@ -94,11 +94,9 @@ class GeneralSettingTiles extends HookConsumerWidget {
|
||||
),
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.general.silentStart),
|
||||
value: ref.watch(silentStartNotifierProvider),
|
||||
value: ref.watch(Preferences.silentStart),
|
||||
onChanged: (value) async {
|
||||
await ref
|
||||
.read(silentStartNotifierProvider.notifier)
|
||||
.update(value);
|
||||
await ref.read(Preferences.silentStart.notifier).update(value);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
@@ -12,7 +12,8 @@ class SettingsInputDialog<T> extends HookConsumerWidget with PresLogger {
|
||||
required this.initialValue,
|
||||
this.mapTo,
|
||||
this.validator,
|
||||
this.resetValue,
|
||||
this.valueFormatter,
|
||||
this.onReset,
|
||||
this.optionalAction,
|
||||
this.icon,
|
||||
this.digitsOnly = false,
|
||||
@@ -22,7 +23,8 @@ class SettingsInputDialog<T> extends HookConsumerWidget with PresLogger {
|
||||
final T initialValue;
|
||||
final T? Function(String value)? mapTo;
|
||||
final bool Function(String value)? validator;
|
||||
final T? resetValue;
|
||||
final String Function(T value)? valueFormatter;
|
||||
final VoidCallback? onReset;
|
||||
final (String text, VoidCallback)? optionalAction;
|
||||
final IconData? icon;
|
||||
final bool digitsOnly;
|
||||
@@ -41,7 +43,7 @@ class SettingsInputDialog<T> extends HookConsumerWidget with PresLogger {
|
||||
final localizations = MaterialLocalizations.of(context);
|
||||
|
||||
final textController = useTextEditingController(
|
||||
text: initialValue?.toString(),
|
||||
text: valueFormatter?.call(initialValue) ?? initialValue.toString(),
|
||||
);
|
||||
|
||||
return FocusTraversalGroup(
|
||||
@@ -74,12 +76,13 @@ class SettingsInputDialog<T> extends HookConsumerWidget with PresLogger {
|
||||
child: Text(optionalAction!.$1.toUpperCase()),
|
||||
),
|
||||
),
|
||||
if (resetValue != null)
|
||||
if (onReset != null)
|
||||
FocusTraversalOrder(
|
||||
order: const NumericFocusOrder(4),
|
||||
child: TextButton(
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).maybePop(resetValue);
|
||||
onReset!();
|
||||
await Navigator.of(context).maybePop(null);
|
||||
},
|
||||
child: Text(t.general.reset.toUpperCase()),
|
||||
),
|
||||
@@ -123,14 +126,14 @@ class SettingsPickerDialog<T> extends HookConsumerWidget with PresLogger {
|
||||
required this.selected,
|
||||
required this.options,
|
||||
required this.getTitle,
|
||||
this.resetValue,
|
||||
this.onReset,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final T selected;
|
||||
final List<T> options;
|
||||
final String Function(T e) getTitle;
|
||||
final T? resetValue;
|
||||
final VoidCallback? onReset;
|
||||
|
||||
Future<T?> show(BuildContext context) async {
|
||||
return showDialog(
|
||||
@@ -162,10 +165,11 @@ class SettingsPickerDialog<T> extends HookConsumerWidget with PresLogger {
|
||||
.toList(),
|
||||
),
|
||||
actions: [
|
||||
if (resetValue != null)
|
||||
if (onReset != null)
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).maybePop(resetValue);
|
||||
onReset!();
|
||||
await Navigator.of(context).maybePop(null);
|
||||
},
|
||||
child: Text(t.general.reset.toUpperCase()),
|
||||
),
|
||||
@@ -186,7 +190,7 @@ class SettingsSliderDialog extends HookConsumerWidget with PresLogger {
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.initialValue,
|
||||
this.resetValue,
|
||||
this.onReset,
|
||||
this.min = 0,
|
||||
this.max = 1,
|
||||
this.divisions,
|
||||
@@ -195,7 +199,7 @@ class SettingsSliderDialog extends HookConsumerWidget with PresLogger {
|
||||
|
||||
final String title;
|
||||
final double initialValue;
|
||||
final double? resetValue;
|
||||
final VoidCallback? onReset;
|
||||
final double min;
|
||||
final double max;
|
||||
final int? divisions;
|
||||
@@ -229,10 +233,11 @@ class SettingsSliderDialog extends HookConsumerWidget with PresLogger {
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
if (resetValue != null)
|
||||
if (onReset != null)
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).maybePop(resetValue);
|
||||
onReset!();
|
||||
await Navigator.of(context).maybePop(null);
|
||||
},
|
||||
child: Text(t.general.reset.toUpperCase()),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user