Facturas recurrentes, edición, padding, y política de privacidad

- Servicio: nuevo campo esRecurrente + migración DB v2
- Al marcar pagada una factura recurrente se genera la siguiente
- Editar facturas existentes desde CrearFacturaScreen
- Nuevo método actualizarFactura en FacturaProvider
- padding inferior en listas de facturas y servicios (último item visible)
- Nota de factura visible en subtítulo
- Filtro Vencidas corregido
- Monto pendiente total visible en dashboard
- Botón undo para revertir factura pagada
- Configuración de release signing (keystore)
- Pantalla de política de privacidad en la app + PRIVACY_POLICY.md
This commit is contained in:
Super User
2026-06-15 21:45:59 -04:00
parent be28ef39cd
commit bbd20f66da
12 changed files with 260 additions and 16 deletions

View File

@@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
import '../models/configuracion.dart';
import '../providers/configuracion_provider.dart';
import '../utils/currency_utils.dart';
import 'privacy_policy_screen.dart';
class ConfiguracionScreen extends StatefulWidget {
const ConfiguracionScreen({super.key});
@@ -64,7 +65,15 @@ class _ConfiguracionScreenState extends State<ConfiguracionScreen> {
onChanged: (v) => setState(() => _moneda = v!),
),
const SizedBox(height: 32),
FilledButton(
const SizedBox(height: 16),
ListTile(
leading: const Icon(Icons.privacy_tip_outlined),
title: const Text('Política de privacidad'),
trailing: const Icon(Icons.chevron_right),
onTap: () => Navigator.push(context, MaterialPageRoute(builder: (_) => const PrivacyPolicyScreen())),
),
const SizedBox(height: 16),
FilledButton(
onPressed: () async {
final diasStr = _opcionesDias
.asMap()

View File

@@ -8,7 +8,8 @@ import '../providers/configuracion_provider.dart';
import '../utils/currency_utils.dart';
class CrearFacturaScreen extends StatefulWidget {
const CrearFacturaScreen({super.key});
final Factura? factura;
const CrearFacturaScreen({super.key, this.factura});
@override
State<CrearFacturaScreen> createState() => _CrearFacturaScreenState();
@@ -28,6 +29,15 @@ class _CrearFacturaScreenState extends State<CrearFacturaScreen> {
super.initState();
_montoCtrl = TextEditingController();
_notaCtrl = TextEditingController();
if (widget.factura != null) {
final f = widget.factura!;
_montoCtrl.text = f.monto.toString();
_notaCtrl.text = f.nota ?? '';
_servicioId = f.servicioId;
_fechaEmision = DateTime.parse(f.fechaEmision);
_fechaVencimiento = DateTime.parse(f.fechaVencimiento);
_estado = f.estado;
}
context.read<ServicioProvider>().cargarServicios();
}
@@ -47,7 +57,7 @@ class _CrearFacturaScreenState extends State<CrearFacturaScreen> {
final symbol = CurrencyUtils.getSymbol(moneda);
return Scaffold(
appBar: AppBar(title: const Text('Nueva factura')),
appBar: AppBar(title: Text(widget.factura != null ? 'Editar factura' : 'Nueva factura')),
body: Form(
key: _formKey,
child: ListView(
@@ -110,18 +120,23 @@ class _CrearFacturaScreenState extends State<CrearFacturaScreen> {
onPressed: () async {
if (!_formKey.currentState!.validate()) return;
final factura = Factura(
id: widget.factura?.id,
servicioId: _servicioId!,
monto: double.parse(_montoCtrl.text),
fechaEmision: DateFormat('yyyy-MM-dd').format(_fechaEmision),
fechaVencimiento: DateFormat('yyyy-MM-dd').format(_fechaVencimiento),
estado: _estado,
nota: _notaCtrl.text.isEmpty ? null : _notaCtrl.text,
fechaPago: _estado == 'Pagada' ? DateFormat('yyyy-MM-dd').format(DateTime.now()) : null,
fechaPago: widget.factura?.fechaPago ?? (_estado == 'Pagada' ? DateFormat('yyyy-MM-dd').format(DateTime.now()) : null),
);
await facturaProv.agregarFactura(factura);
if (widget.factura != null) {
await facturaProv.actualizarFactura(factura);
} else {
await facturaProv.agregarFactura(factura);
}
if (context.mounted) Navigator.pop(context);
},
child: const Text('Guardar factura'),
child: Text(widget.factura != null ? 'Guardar cambios' : 'Guardar factura'),
),
],
),

View File

@@ -18,6 +18,7 @@ class _CrearServicioScreenState extends State<CrearServicioScreen> {
String _iconoSeleccionado = 'recibo';
Color _colorSeleccionado = Colors.purple;
int _diaVencimiento = 15;
bool _esRecurrente = false;
final List<Map<String, dynamic>> _iconos = [
{'key': 'electricidad', 'icon': Icons.bolt, 'label': 'Electricidad'},
@@ -46,6 +47,7 @@ class _CrearServicioScreenState extends State<CrearServicioScreen> {
_iconoSeleccionado = widget.servicio!.icono;
_colorSeleccionado = Color(widget.servicio!.color);
_diaVencimiento = widget.servicio!.diaVencimiento;
_esRecurrente = widget.servicio!.esRecurrente;
}
}
@@ -111,6 +113,13 @@ class _CrearServicioScreenState extends State<CrearServicioScreen> {
);
}).toList(),
),
const SizedBox(height: 8),
SwitchListTile(
title: const Text('Factura recurrente'),
subtitle: const Text('Generar automáticamente la siguiente factura al pagar'),
value: _esRecurrente,
onChanged: (v) => setState(() => _esRecurrente = v),
),
const SizedBox(height: 20),
Text('Día de vencimiento', style: Theme.of(context).textTheme.titleSmall),
const SizedBox(height: 8),
@@ -131,6 +140,7 @@ class _CrearServicioScreenState extends State<CrearServicioScreen> {
color: _colorSeleccionado.value,
diaVencimiento: _diaVencimiento,
fechaCreacion: widget.servicio?.fechaCreacion ?? DateFormat('yyyy-MM-dd').format(DateTime.now()),
esRecurrente: _esRecurrente,
);
if (widget.servicio != null) {
await provider.actualizarServicio(servicio);

View File

@@ -39,6 +39,9 @@ class _DashboardScreenState extends State<DashboardScreen> {
final moneda = configProv.config?.moneda ?? 'USD';
final pendientes = facturaProv.facturas.where((f) => f.estado == 'Pendiente').length;
final pendienteTotal = facturaProv.facturas
.where((f) => f.estado == 'Pendiente')
.fold(0.0, (sum, f) => sum + f.monto);
final vencidas = facturaProv.facturasVencidas.length;
return Scaffold(
@@ -48,7 +51,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
body: RefreshIndicator(
onRefresh: () async => _cargarDatos(),
child: ListView(
padding: const EdgeInsets.all(16),
padding: const EdgeInsets.fromLTRB(16, 16, 16, 80),
children: [
Row(
children: [
@@ -95,6 +98,11 @@ class _DashboardScreenState extends State<DashboardScreen> {
Icon(Icons.event_note, size: 20, color: Theme.of(context).colorScheme.primary),
const SizedBox(width: 8),
Text('Próximos vencimientos', style: Theme.of(context).textTheme.titleMedium),
const Spacer(),
Text(CurrencyUtils.formatPrice(pendienteTotal, moneda),
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: Theme.of(context).colorScheme.primary)),
],
),
const SizedBox(height: 12),

View File

@@ -4,6 +4,7 @@ import '../providers/factura_provider.dart';
import '../providers/servicio_provider.dart';
import '../providers/configuracion_provider.dart';
import '../utils/currency_utils.dart';
import 'crear_factura_screen.dart';
class FacturasScreen extends StatefulWidget {
const FacturasScreen({super.key});
@@ -45,7 +46,7 @@ class _FacturasScreenState extends State<FacturasScreen> {
const SizedBox(width: 8),
FilterChip(label: const Text('Pagadas'), selected: _filtroEstado == 'Pagada', onSelected: (_) => setState(() { _filtroEstado = 'Pagada'; _filtroServicio = null; facturaProv.cargarFacturas(estado: 'Pagada'); })),
const SizedBox(width: 8),
FilterChip(label: const Text('Vencidas'), selected: _filtroEstado == 'vencidas', onSelected: (_) => setState(() { _filtroEstado = 'vencidas'; _filtroServicio = null; facturaProv.facturasVencidas; })),
FilterChip(label: const Text('Vencidas'), selected: _filtroEstado == 'vencidas', onSelected: (_) => setState(() { _filtroEstado = 'vencidas'; _filtroServicio = null; facturaProv.cargarFacturas(estado: 'vencidas'); })),
],
),
),
@@ -54,7 +55,7 @@ class _FacturasScreenState extends State<FacturasScreen> {
child: facturaProv.cargando
? const Center(child: CircularProgressIndicator())
: ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 16),
padding: const EdgeInsets.fromLTRB(16, 0, 16, 80),
itemCount: facturaProv.facturas.length + (facturaProv.facturas.isEmpty ? 1 : 0),
itemBuilder: (_, i) {
if (facturaProv.facturas.isEmpty) {
@@ -97,7 +98,13 @@ class _FacturasScreenState extends State<FacturasScreen> {
),
title: Text('${servicio?.nombre ?? 'Desconocido'} - ${CurrencyUtils.formatPrice(f.monto, moneda)}',
style: const TextStyle(fontWeight: FontWeight.w500)),
subtitle: Text('Vence: ${f.fechaVencimiento}${f.estado == 'Pagada' ? ' Pagada: ${f.fechaPago ?? ''}' : ''}'),
subtitle: Text.rich(TextSpan(children: [
TextSpan(text: 'Vence: ${f.fechaVencimiento}'),
if (f.estado == 'Pagada' && f.fechaPago != null)
TextSpan(text: ' Pagada: ${f.fechaPago}'),
if (f.nota != null && f.nota!.isNotEmpty)
TextSpan(text: '\n${f.nota}', style: TextStyle(color: Colors.grey[600], fontSize: 12)),
])),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
@@ -105,7 +112,17 @@ class _FacturasScreenState extends State<FacturasScreen> {
IconButton(
icon: Icon(Icons.check_circle, color: vencida ? Colors.red : Colors.green),
onPressed: () => facturaProv.marcarPagada(f.id!),
)
else
IconButton(
icon: const Icon(Icons.undo, color: Colors.orange),
onPressed: () => facturaProv.marcarPendiente(f.id!),
tooltip: 'Marcar pendiente',
),
IconButton(
icon: const Icon(Icons.edit_outlined),
onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (_) => CrearFacturaScreen(factura: f))).then((_) => facturaProv.cargarFacturas()),
),
IconButton(
icon: const Icon(Icons.delete_outline, color: Colors.red),
onPressed: () => facturaProv.eliminarFactura(f.id!),

View File

@@ -0,0 +1,62 @@
import 'package:flutter/material.dart';
class PrivacyPolicyScreen extends StatelessWidget {
const PrivacyPolicyScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Política de Privacidad')),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
Text('Factura del Hogar', style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold)),
const SizedBox(height: 24),
_section(context, 'Recolección de datos',
'Factura del Hogar no recolecta, transmite ni comparte ningún dato personal. '
'Toda la información que ingresas (facturas, servicios, montos y configuración) '
'se almacena exclusivamente en tu dispositivo usando una base de datos SQLite local.'),
const SizedBox(height: 16),
_section(context, 'Acceso a Internet',
'La aplicación no requiere acceso a Internet. El permiso INTERNET solo se '
'declara en builds de depuración (requerido por Flutter para recarga en caliente). '
'La versión de distribución en Google Play no tiene permiso de Internet ni '
'capacidades de red.'),
const SizedBox(height: 16),
_section(context, 'Permisos',
'• POST_NOTIFICATIONS: Para mostrar recordatorios locales de vencimiento de facturas.\n'
'• RECEIVE_BOOT_COMPLETED: Para reprogramar notificaciones después de reiniciar el dispositivo.\n'
'• SCHEDULE_EXACT_ALARM: Para entregar recordatorios a la hora exacta programada.\n\n'
'Ningún permiso se usa para acceder a Internet, cuentas o almacenamiento externo.'),
const SizedBox(height: 16),
_section(context, 'Servicios de terceros',
'Esta aplicación no usa servicios de análisis, publicidad ni rastreo de terceros. '
'No se envía ningún dato a ningún servidor.'),
const SizedBox(height: 16),
_section(context, 'Eliminación de datos',
'Como todos los datos se almacenan localmente, desinstalar la aplicación elimina '
'todos los datos asociados. También puedes eliminar facturas o servicios '
'individualmente desde la interfaz de la aplicación.'),
const SizedBox(height: 16),
_section(context, 'Contacto',
'Si tienes preguntas sobre esta política de privacidad, abre un issue en el '
'repositorio del proyecto.'),
const SizedBox(height: 16),
Text('Última actualización: Junio 2026', style: Theme.of(context).textTheme.bodySmall?.copyWith(color: Colors.grey)),
const SizedBox(height: 32),
],
),
);
}
Widget _section(BuildContext context, String title, String body) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: Theme.of(context).textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w600)),
const SizedBox(height: 4),
Text(body, style: Theme.of(context).textTheme.bodyMedium),
],
);
}
}

View File

@@ -28,7 +28,7 @@ class ServiciosScreen extends StatelessWidget {
),
)
: ListView.builder(
padding: const EdgeInsets.all(16),
padding: const EdgeInsets.fromLTRB(16, 16, 16, 80),
itemCount: provider.servicios.length,
itemBuilder: (_, i) {
final s = provider.servicios[i];