mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 07:44:26 +01:00
opt.: detect sync conflict
This commit is contained in:
@@ -150,7 +150,14 @@ class BackupPage extends StatelessWidget {
|
||||
title: Text(l10n.auto),
|
||||
trailing: StoreSwitch(
|
||||
prop: Stores.setting.icloudSync,
|
||||
func: (val) async {
|
||||
validator: (p0) {
|
||||
if (p0 && Stores.setting.webdavSync.fetch()) {
|
||||
context.showSnackBar(l10n.autoBackupConflict);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
callback: (val) async {
|
||||
if (val) {
|
||||
icloudLoading.value = true;
|
||||
await ICloud.sync();
|
||||
@@ -273,24 +280,20 @@ class BackupPage extends StatelessWidget {
|
||||
},
|
||||
child: Text(l10n.ok),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
final result = await Webdav.test(
|
||||
urlCtrl.text,
|
||||
userCtrl.text,
|
||||
pwdCtrl.text,
|
||||
);
|
||||
if (result == null) {
|
||||
context.showSnackBar(l10n.success);
|
||||
} else {
|
||||
context.showSnackBar(result);
|
||||
}
|
||||
},
|
||||
child: Text(l10n.test),
|
||||
),
|
||||
],
|
||||
);
|
||||
if (result == true) {
|
||||
final result = await Webdav.test(
|
||||
urlCtrl.text,
|
||||
userCtrl.text,
|
||||
pwdCtrl.text,
|
||||
);
|
||||
if (result == null) {
|
||||
context.showSnackBar(l10n.success);
|
||||
} else {
|
||||
context.showSnackBar(result);
|
||||
return;
|
||||
}
|
||||
Webdav.changeClient(
|
||||
urlCtrl.text,
|
||||
userCtrl.text,
|
||||
@@ -306,7 +309,22 @@ class BackupPage extends StatelessWidget {
|
||||
title: Text(l10n.auto),
|
||||
trailing: StoreSwitch(
|
||||
prop: Stores.setting.webdavSync,
|
||||
func: (val) async {
|
||||
validator: (p0) {
|
||||
if (p0) {
|
||||
if (Stores.setting.webdavUrl.fetch().isEmpty ||
|
||||
Stores.setting.webdavUser.fetch().isEmpty ||
|
||||
Stores.setting.webdavPwd.fetch().isEmpty) {
|
||||
context.showSnackBar(l10n.webdavSettingEmpty);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (Stores.setting.icloudSync.fetch()) {
|
||||
context.showSnackBar(l10n.autoBackupConflict);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
callback: (val) async {
|
||||
if (val) {
|
||||
webdavLoading.value = true;
|
||||
await Webdav.sync();
|
||||
|
||||
@@ -339,7 +339,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
title: Text(l10n.followSystem),
|
||||
trailing: StoreSwitch(
|
||||
prop: _setting.useSystemPrimaryColor,
|
||||
func: (_) => setState(() {}),
|
||||
callback: (_) => setState(() {}),
|
||||
),
|
||||
)
|
||||
];
|
||||
@@ -747,7 +747,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
title: Text(l10n.fullScreen),
|
||||
trailing: StoreSwitch(
|
||||
prop: _setting.fullScreen,
|
||||
func: (_) => RebuildNodes.app.rebuild(),
|
||||
callback: (_) => RebuildNodes.app.rebuild(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class PlatformPublicSettings {
|
||||
trailing: can == true
|
||||
? StoreSwitch(
|
||||
prop: Stores.setting.useBioAuth,
|
||||
func: (val) async {
|
||||
callback: (val) async {
|
||||
if (val) {
|
||||
Stores.setting.useBioAuth.put(false);
|
||||
return;
|
||||
|
||||
@@ -4,9 +4,19 @@ import '../../core/persistant_store.dart';
|
||||
|
||||
class StoreSwitch extends StatelessWidget {
|
||||
final StorePropertyBase<bool> prop;
|
||||
final void Function(bool)? func;
|
||||
|
||||
const StoreSwitch({super.key, required this.prop, this.func});
|
||||
/// Exec before make change, after validator.
|
||||
final void Function(bool)? callback;
|
||||
|
||||
/// If return false, the switch will not change.
|
||||
final bool Function(bool)? validator;
|
||||
|
||||
const StoreSwitch({
|
||||
super.key,
|
||||
required this.prop,
|
||||
this.callback,
|
||||
this.validator,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -16,7 +26,8 @@ class StoreSwitch extends StatelessWidget {
|
||||
return Switch(
|
||||
value: value,
|
||||
onChanged: (value) {
|
||||
func?.call(value);
|
||||
if (validator != null && validator?.call(value) != true) return;
|
||||
callback?.call(value);
|
||||
prop.put(value);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user