feat: replace json tools with local data controls

This commit is contained in:
2026-06-12 01:11:50 +08:00
parent b88b947e66
commit b287a56731
10 changed files with 415 additions and 254 deletions
+13 -60
View File
@@ -1,9 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../core/json_utils.dart';
import '../l10n/l10n.dart';
import '../models/app_state.dart';
Future<void> showHabitDialog(
BuildContext context,
@@ -123,64 +120,16 @@ Future<void> confirmDeleteHabit(
);
}
Future<void> showExportDialog(BuildContext context, AppState state) async {
final scaffoldContext = context;
final export = prettyJson(state.toJson());
await showDialog<void>(
context: context,
builder:
(context) => AlertDialog(
title: Text(context.l10n.exportJson),
content: SizedBox(
width: double.maxFinite,
child: SingleChildScrollView(
child: SelectableText(
export,
style: const TextStyle(fontFamily: 'monospace'),
),
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(context.l10n.close),
),
FilledButton.icon(
onPressed: () async {
final message = context.l10n.exportCopied;
await Clipboard.setData(ClipboardData(text: export));
if (context.mounted) {
Navigator.pop(context);
showSnack(scaffoldContext, message);
}
},
icon: const Icon(Icons.copy),
label: Text(context.l10n.copy),
),
],
),
);
}
Future<void> showImportDialog(
Future<void> confirmClearToday(
BuildContext context,
ValueChanged<String> onImport,
VoidCallback onConfirm,
) async {
var value = '';
await showDialog<void>(
context: context,
builder:
(context) => AlertDialog(
title: Text(context.l10n.importJson),
content: TextFormField(
minLines: 8,
maxLines: 12,
onChanged: (nextValue) => value = nextValue,
decoration: InputDecoration(
border: const OutlineInputBorder(),
hintText: context.l10n.importHint,
),
),
title: Text(context.l10n.clearTodayDataTitle),
content: Text(context.l10n.clearTodayDataBody),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
@@ -188,10 +137,10 @@ Future<void> showImportDialog(
),
FilledButton(
onPressed: () {
onImport(value);
onConfirm();
Navigator.pop(context);
},
child: Text(context.l10n.import),
child: Text(context.l10n.clearToday),
),
],
),
@@ -206,19 +155,23 @@ Future<void> confirmClearData(
context: context,
builder:
(context) => AlertDialog(
title: Text(context.l10n.clearDataTitle),
content: Text(context.l10n.clearDataBody),
title: Text(context.l10n.clearAllDataTitle),
content: Text(context.l10n.clearAllDataBody),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(context.l10n.cancel),
),
FilledButton(
style: FilledButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.error,
foregroundColor: Theme.of(context).colorScheme.onError,
),
onPressed: () {
onConfirm();
Navigator.pop(context);
},
child: Text(context.l10n.clear),
child: Text(context.l10n.deleteAll),
),
],
),