Make network auto control setting reactive with proper GetX observable

Co-authored-by: monkeyWie <[email protected]>
This commit is contained in:
copilot-swe-agent[bot]andmonkeyWie committed 2025-08-11 08:11:00 +00:00
1 parent 14df9490cf
commit 27dc7aea52
2 files changed
+14 -6

No files matched your search

@@ -1,15 +1,19 @@
import 'package:get/get.dart';
import '../../../../database/database.dart';
import '../../../../util/updater.dart';
class SettingController extends GetxController {
final tapStatues = <String, bool>{}.obs;
final latestVersion = Rxn<VersionInfo>();
final networkAutoControl = false.obs;
@override
void onInit() {
super.onInit();
fetchLatestVersion();
// Initialize network auto control setting
networkAutoControl.value = Database.instance.getNetworkAutoControl();
}
// set all tap status to false
@@ -27,4 +31,10 @@ class SettingController extends GetxController {
void fetchLatestVersion() async {
latestVersion.value = await checkUpdate();
}
// update network auto control setting
void updateNetworkAutoControl(bool value) {
networkAutoControl.value = value;
Database.instance.saveNetworkAutoControl(value);
}
}
@@ -550,18 +550,16 @@ class SettingView extends GetView<SettingController> {
return null;
}
return ListTile(
return Obx(() => ListTile(
title: Text('networkAutoControl'.tr),
subtitle: Text('networkAutoControlTip'.tr),
trailing: Switch(
value: Database.instance.getNetworkAutoControl(),
value: controller.networkAutoControl.value,
onChanged: (bool value) {
Database.instance.saveNetworkAutoControl(value);
// Trigger rebuild to update the display value
controller.update();
controller.updateNetworkAutoControl(value);
},
),
);
));
}
// advanced config proxy items start