opt.: sync switch

This commit is contained in:
lollipopkit
2023-12-05 10:49:14 +08:00
parent 03b9a46a4c
commit 143cb1e7c1
5 changed files with 40 additions and 31 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import '../../core/persistant_store.dart';
@@ -6,7 +8,7 @@ class StoreSwitch extends StatelessWidget {
final StorePropertyBase<bool> prop;
/// Exec before make change, after validator.
final void Function(bool)? callback;
final FutureOr<void> Function(bool)? callback;
/// If return false, the switch will not change.
final bool Function(bool)? validator;
@@ -25,9 +27,9 @@ class StoreSwitch extends StatelessWidget {
builder: (context, bool value, widget) {
return Switch(
value: value,
onChanged: (value) {
onChanged: (value) async {
if (validator != null && validator?.call(value) != true) return;
callback?.call(value);
await callback?.call(value);
prop.put(value);
},
);