mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
opt.: detect sync conflict
This commit is contained in:
@@ -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