mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 22:33:42 +00:00
Make network auto control setting reactive with proper GetX observable
Co-authored-by: monkeyWie <[email protected]>
This commit is contained in:
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 'package:get/get.dart';
|
||||||
|
|
||||||
|
import '../../../../database/database.dart';
|
||||||
import '../../../../util/updater.dart';
|
import '../../../../util/updater.dart';
|
||||||
|
|
||||||
class SettingController extends GetxController {
|
class SettingController extends GetxController {
|
||||||
final tapStatues = <String, bool>{}.obs;
|
final tapStatues = <String, bool>{}.obs;
|
||||||
final latestVersion = Rxn<VersionInfo>();
|
final latestVersion = Rxn<VersionInfo>();
|
||||||
|
final networkAutoControl = false.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
fetchLatestVersion();
|
fetchLatestVersion();
|
||||||
|
// Initialize network auto control setting
|
||||||
|
networkAutoControl.value = Database.instance.getNetworkAutoControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
// set all tap status to false
|
// set all tap status to false
|
||||||
@@ -27,4 +31,10 @@ class SettingController extends GetxController {
|
|||||||
void fetchLatestVersion() async {
|
void fetchLatestVersion() async {
|
||||||
latestVersion.value = await checkUpdate();
|
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 null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ListTile(
|
return Obx(() => ListTile(
|
||||||
title: Text('networkAutoControl'.tr),
|
title: Text('networkAutoControl'.tr),
|
||||||
subtitle: Text('networkAutoControlTip'.tr),
|
subtitle: Text('networkAutoControlTip'.tr),
|
||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: Database.instance.getNetworkAutoControl(),
|
value: controller.networkAutoControl.value,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
Database.instance.saveNetworkAutoControl(value);
|
controller.updateNetworkAutoControl(value);
|
||||||
// Trigger rebuild to update the display value
|
|
||||||
controller.update();
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// advanced config proxy items start
|
// advanced config proxy items start
|
||||||
|
|||||||
Reference in new issue
Block a user