111 lines
3.5 KiB
Dart
111 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:notas/widgets/search_app_bar.dart';
|
|
|
|
class SettingsScreen extends StatefulWidget {
|
|
const SettingsScreen({
|
|
super.key,
|
|
required this.onDeleteAllData,
|
|
required this.onBackToHome,
|
|
});
|
|
|
|
final Future<void> Function() onDeleteAllData;
|
|
final VoidCallback onBackToHome;
|
|
|
|
@override
|
|
State<SettingsScreen> createState() => _SettingsScreenState();
|
|
}
|
|
|
|
class _SettingsScreenState extends State<SettingsScreen> {
|
|
bool _isBusy = false;
|
|
|
|
Future<void> _confirmAndDeleteAll() async {
|
|
final bool? confirmed = await showDialog<bool>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Borrar todos los datos'),
|
|
content: const Text('¿Estás seguro? Esta acción eliminará la base de datos local y la clave de cifrado. No se podrá recuperar.'),
|
|
actions: [
|
|
TextButton(onPressed: () => Navigator.of(context).pop(false), child: const Text('Cancelar')),
|
|
TextButton(onPressed: () => Navigator.of(context).pop(true), child: const Text('Borrar', style: TextStyle(color: Colors.red))),
|
|
],
|
|
),
|
|
);
|
|
|
|
if (confirmed != true) return;
|
|
|
|
setState(() {
|
|
_isBusy = true;
|
|
});
|
|
|
|
try {
|
|
await widget.onDeleteAllData();
|
|
|
|
if (!mounted) return;
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Todos los datos locales han sido eliminados.')),
|
|
);
|
|
} catch (error) {
|
|
if (!mounted) return;
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text('Error al borrar los datos: $error')),
|
|
);
|
|
} finally {
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_isBusy = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Container(
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
colors: [
|
|
Color(0xFF191A1D),
|
|
Color(0xFF222326),
|
|
Color(0xFF101114),
|
|
],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
),
|
|
child: SafeArea(
|
|
child: Column(
|
|
children: [
|
|
SearchAppBar(
|
|
onLeadingPressed: widget.onBackToHome,
|
|
leadingIcon: Icons.arrow_back,
|
|
leadingTooltip: 'Atrás',
|
|
showSearch: false,
|
|
titleText: 'Configuración',
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
ElevatedButton.icon(
|
|
style: ElevatedButton.styleFrom(backgroundColor: Colors.redAccent),
|
|
onPressed: _isBusy ? null : _confirmAndDeleteAll,
|
|
icon: _isBusy ? const SizedBox(width: 16, height: 16, child: CircularProgressIndicator(strokeWidth: 2)) : const Icon(Icons.delete_forever),
|
|
label: const Text('Borrar todos los datos'),
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Text('Esto cerrará el vault actual y eliminará la base de datos local junto con la clave de cifrado.'),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|