fixes before build 3
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
||||
import '../services/app_settings.dart';
|
||||
import '../services/backup_service.dart';
|
||||
import '../supermarkets_screen.dart';
|
||||
import 'confirm_dialog.dart';
|
||||
|
||||
class SettingsButton extends StatelessWidget {
|
||||
const SettingsButton({super.key});
|
||||
@@ -104,6 +105,36 @@ class _SettingsSheetState extends State<_SettingsSheet> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _wipeAllData(AppSettings settings) async {
|
||||
final confirmed = await confirmAction(
|
||||
context,
|
||||
title: 'Delete all data?',
|
||||
message:
|
||||
'This permanently removes all products, shopping trips, lists, '
|
||||
'photos, bonus cards, and settings on this device. '
|
||||
'Export a backup first if you want to keep anything.',
|
||||
confirmLabel: 'Delete everything',
|
||||
);
|
||||
if (!confirmed || !mounted) return;
|
||||
|
||||
setState(() => _busy = true);
|
||||
try {
|
||||
await settings.wipeAllData();
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('All data deleted.')),
|
||||
);
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Could not delete all data.')),
|
||||
);
|
||||
} finally {
|
||||
if (mounted) setState(() => _busy = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _openSupermarkets(BuildContext context, AppSettings settings) {
|
||||
Navigator.of(context)
|
||||
..pop()
|
||||
@@ -117,18 +148,20 @@ class _SettingsSheetState extends State<_SettingsSheet> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final settings = SettingsScope.of(context);
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final bottom = MediaQuery.viewInsetsOf(context).bottom;
|
||||
final maxHeight = MediaQuery.sizeOf(context).height * 0.85;
|
||||
|
||||
return ListenableBuilder(
|
||||
listenable: settings,
|
||||
builder: (context, _) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.fromLTRB(16, 0, 16, 16 + bottom),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
return SizedBox(
|
||||
height: maxHeight,
|
||||
child: ListView(
|
||||
padding: EdgeInsets.fromLTRB(16, 0, 16, 16 + bottom),
|
||||
children: [
|
||||
Text('Settings', style: Theme.of(context).textTheme.titleLarge),
|
||||
Text('Settings', style: theme.textTheme.titleLarge),
|
||||
const SizedBox(height: 8),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
@@ -151,10 +184,10 @@ class _SettingsSheetState extends State<_SettingsSheet> {
|
||||
: () => _openSupermarkets(context, settings),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('Backup', style: Theme.of(context).textTheme.titleMedium),
|
||||
Text('Backup', style: theme.textTheme.titleMedium),
|
||||
Text(
|
||||
'Save everything to a JSON file, or replace this device from a backup.',
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
@@ -180,6 +213,28 @@ class _SettingsSheetState extends State<_SettingsSheet> {
|
||||
const SizedBox(height: 8),
|
||||
const LinearProgressIndicator(),
|
||||
],
|
||||
const SizedBox(height: 32),
|
||||
Text(
|
||||
'Danger zone',
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
color: scheme.error,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'Permanently delete everything on this device.',
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
OutlinedButton.icon(
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: scheme.error,
|
||||
side: BorderSide(color: scheme.error),
|
||||
),
|
||||
onPressed: _busy ? null : () => _wipeAllData(settings),
|
||||
icon: const Icon(Icons.delete_forever_outlined),
|
||||
label: const Text('Delete all data'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user