reset direct dns when region change

This commit is contained in:
hiddify-com
2024-07-27 23:51:54 +02:00
parent c4f8ebeaf4
commit bdb69a603a
6 changed files with 35 additions and 26 deletions

View File

@@ -71,6 +71,7 @@ abstract class ConfigOptions {
static final directDnsAddress = PreferencesNotifier.create<String, String>(
"direct-dns-address",
"1.1.1.1",
defaultValueFunction: (ref) => ref.read(region) == Region.cn ? "223.5.5.5" : "1.1.1.1",
validator: (value) => value.isNotBlank,
);

View File

@@ -146,6 +146,7 @@ class ConfigOptionsPage extends HookConsumerWidget {
choices: Region.values,
title: t.settings.general.region,
presentChoice: (value) => value.present(t),
onChanged: (val) => ref.watch(ConfigOptions.directDnsAddress.notifier).reset(),
),
SwitchListTile(
title: Text(experimental(t.config.blockAds)),

View File

@@ -61,6 +61,7 @@ class ChoicePreferenceWidget<T> extends StatelessWidget {
required this.title,
required this.presentChoice,
this.validateInput,
this.onChanged,
});
final T selected;
@@ -70,7 +71,7 @@ class ChoicePreferenceWidget<T> extends StatelessWidget {
final String title;
final String Function(T value) presentChoice;
final bool Function(String value)? validateInput;
final ValueChanged<T>? onChanged;
@override
Widget build(BuildContext context) {
return ListTile(
@@ -88,7 +89,9 @@ class ChoicePreferenceWidget<T> extends StatelessWidget {
if (selection == null) {
return;
}
await preferences.update(selection);
final out = await preferences.update(selection);
onChanged?.call(selection);
return out;
},
);
}