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

@@ -44,6 +44,7 @@ class BackupPage extends StatelessWidget {
return ListView(
padding: const EdgeInsets.all(17),
children: [
_buildTip(),
if (isMacOS || isIOS) _buildIcloud(context),
_buildWebdav(context),
_buildFile(context),
@@ -51,6 +52,16 @@ class BackupPage extends StatelessWidget {
);
}
Widget _buildTip() {
return CardX(
ListTile(
leading: const Icon(Icons.warning),
title: Text(l10n.attention),
subtitle: Text(l10n.backupTip, style: UIs.textGrey),
),
);
}
Widget _buildFile(BuildContext context) {
return CardX(
ExpandTile(
@@ -61,10 +72,6 @@ class BackupPage extends StatelessWidget {
ListTile(
title: Text(l10n.backup),
trailing: const Icon(Icons.save),
subtitle: Text(
l10n.backupTip,
style: UIs.textGrey,
),
onTap: () async {
final path = await Backup.backup();

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