opt.: detect sync conflict

This commit is contained in:
lollipopkit
2023-12-04 14:36:32 +08:00
parent 38cdef9458
commit 22901bb856
14 changed files with 104 additions and 23 deletions

View File

@@ -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);
},
);