PACKET v1.0.0 - Initial release
App móvil Flutter para capturar contenido multimedia, etiquetarlo con hashes y enviarlo a backends configurables. Features: - Captura de fotos, audio, video y archivos - Sistema de etiquetas con bibliotecas externas (HST) - Packs de etiquetas predefinidos - Cola de reintentos (hasta 20 contenedores) - Soporte GPS - Hash SHA-256 auto-generado por contenedor - Persistencia SQLite local - Múltiples destinos configurables Stack: Flutter 3.38.5, flutter_bloc, sqflite, dio 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
311
lib/presentation/pages/captura_page.dart
Normal file
311
lib/presentation/pages/captura_page.dart
Normal file
@@ -0,0 +1,311 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../bloc/captura/captura_cubit.dart';
|
||||
import '../bloc/captura/captura_state.dart';
|
||||
import '../bloc/etiquetas/etiquetas_cubit.dart';
|
||||
import '../bloc/app/app_cubit.dart';
|
||||
import '../bloc/app/app_state.dart';
|
||||
import '../widgets/audio_recorder.dart';
|
||||
import '../../core/utils/hash_utils.dart';
|
||||
|
||||
class CapturaPage extends StatelessWidget {
|
||||
const CapturaPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<CapturaCubit, CapturaState>(
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// Hash section
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.tag, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
const Text('Hash', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.copy, size: 20),
|
||||
onPressed: () {
|
||||
Clipboard.setData(ClipboardData(text: state.contenedor.hash));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Hash copiado')),
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh, size: 20),
|
||||
onPressed: () => context.read<CapturaCubit>().regenerateHash(),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
HashUtils.truncateHash(state.contenedor.hash, length: 32),
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
fontFamily: 'monospace',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Title & Description
|
||||
TextField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Título (opcional)',
|
||||
prefixIcon: Icon(Icons.title),
|
||||
),
|
||||
onChanged: (v) => context.read<CapturaCubit>().setTitulo(v),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Descripción (opcional)',
|
||||
prefixIcon: Icon(Icons.description),
|
||||
),
|
||||
maxLines: 2,
|
||||
onChanged: (v) => context.read<CapturaCubit>().setDescripcion(v),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Capture buttons
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Capturar', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
_CaptureButton(
|
||||
icon: Icons.camera_alt,
|
||||
label: 'Foto',
|
||||
onPressed: () => context.read<CapturaCubit>().capturePhoto(),
|
||||
),
|
||||
AudioRecorderButton(
|
||||
onRecorded: (bytes, name) {
|
||||
context.read<CapturaCubit>().addAudioFile(bytes, name);
|
||||
},
|
||||
),
|
||||
_CaptureButton(
|
||||
icon: Icons.videocam,
|
||||
label: 'Video',
|
||||
onPressed: () => context.read<CapturaCubit>().captureVideo(),
|
||||
),
|
||||
_CaptureButton(
|
||||
icon: Icons.attach_file,
|
||||
label: 'Archivo',
|
||||
onPressed: () => context.read<CapturaCubit>().pickFile(),
|
||||
),
|
||||
_CaptureButton(
|
||||
icon: state.contenedor.gps != null
|
||||
? Icons.location_on
|
||||
: Icons.location_off,
|
||||
label: 'GPS',
|
||||
onPressed: () {
|
||||
if (state.contenedor.gps != null) {
|
||||
context.read<CapturaCubit>().clearGps();
|
||||
} else {
|
||||
context.read<CapturaCubit>().captureGps();
|
||||
}
|
||||
},
|
||||
selected: state.contenedor.gps != null,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Attached files
|
||||
if (state.contenedor.archivos.isNotEmpty) ...[
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Archivos (${state.contenedor.archivos.length})',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
...state.contenedor.archivos.asMap().entries.map((e) {
|
||||
final archivo = e.value;
|
||||
return ListTile(
|
||||
leading: Icon(_getFileIcon(archivo.tipo)),
|
||||
title: Text(archivo.nombre),
|
||||
subtitle: Text(archivo.sizeFormatted),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () =>
|
||||
context.read<CapturaCubit>().removeArchivo(e.key),
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
// Etiquetas summary
|
||||
BlocBuilder<EtiquetasCubit, dynamic>(
|
||||
builder: (context, etState) {
|
||||
final seleccionadas = (etState as dynamic).seleccionadas as List<String>;
|
||||
if (seleccionadas.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Etiquetas (${seleccionadas.length})',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: seleccionadas
|
||||
.map((h) => Chip(
|
||||
label: Text(HashUtils.truncateHash(h)),
|
||||
onDeleted: () =>
|
||||
context.read<EtiquetasCubit>().removeEtiqueta(h),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
// GPS info
|
||||
if (state.contenedor.gps != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.location_on, color: Colors.green),
|
||||
title: const Text('Ubicación'),
|
||||
subtitle: Text(state.contenedor.gps!.toString()),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Send button
|
||||
BlocBuilder<AppCubit, AppState>(
|
||||
builder: (context, appState) {
|
||||
final destino = appState.destinoActivo;
|
||||
return FilledButton.icon(
|
||||
onPressed: destino != null && state.status != CapturaStatus.sending
|
||||
? () {
|
||||
final etiquetas = context
|
||||
.read<EtiquetasCubit>()
|
||||
.state
|
||||
.seleccionadas;
|
||||
context.read<CapturaCubit>().setEtiquetas(etiquetas);
|
||||
context.read<CapturaCubit>().enviar(destino);
|
||||
}
|
||||
: null,
|
||||
icon: state.status == CapturaStatus.sending
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.send),
|
||||
label: Text(state.status == CapturaStatus.sending
|
||||
? 'Enviando...'
|
||||
: 'Enviar'),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
if (state.status == CapturaStatus.error && state.errorMessage != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: Text(
|
||||
state.errorMessage!,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
IconData _getFileIcon(dynamic tipo) {
|
||||
switch (tipo.toString()) {
|
||||
case 'FileType.image':
|
||||
return Icons.image;
|
||||
case 'FileType.audio':
|
||||
return Icons.audiotrack;
|
||||
case 'FileType.video':
|
||||
return Icons.videocam;
|
||||
default:
|
||||
return Icons.insert_drive_file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _CaptureButton extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final VoidCallback onPressed;
|
||||
final bool selected;
|
||||
|
||||
const _CaptureButton({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.onPressed,
|
||||
this.selected = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FilledButton.tonal(
|
||||
onPressed: onPressed,
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: selected ? Theme.of(context).colorScheme.primaryContainer : null,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 18),
|
||||
const SizedBox(width: 4),
|
||||
Text(label),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
303
lib/presentation/pages/config_page.dart
Normal file
303
lib/presentation/pages/config_page.dart
Normal file
@@ -0,0 +1,303 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../bloc/app/app_cubit.dart';
|
||||
import '../bloc/app/app_state.dart';
|
||||
import '../bloc/etiquetas/etiquetas_cubit.dart';
|
||||
import '../bloc/etiquetas/etiquetas_state.dart';
|
||||
import '../../domain/entities/destino.dart';
|
||||
import '../../domain/entities/biblioteca.dart';
|
||||
import '../../data/repositories/config_repository.dart';
|
||||
|
||||
class ConfigPage extends StatelessWidget {
|
||||
const ConfigPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
// Destinos section
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.cloud_upload),
|
||||
const SizedBox(width: 8),
|
||||
const Text(
|
||||
'Destinos',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () => _showDestinoDialog(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
BlocBuilder<AppCubit, AppState>(
|
||||
builder: (context, state) {
|
||||
if (state.destinos.isEmpty) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Text('No hay destinos configurados'),
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
children: state.destinos.map((destino) {
|
||||
final isActive = state.destinoActivo?.id == destino.id;
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
isActive ? Icons.radio_button_checked : Icons.radio_button_off,
|
||||
color: isActive ? Theme.of(context).colorScheme.primary : null,
|
||||
),
|
||||
title: Text(destino.nombre),
|
||||
subtitle: Text(
|
||||
destino.url,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
onPressed: () => context.read<AppCubit>().removeDestino(destino.id!),
|
||||
),
|
||||
onTap: () => context.read<AppCubit>().setDestinoActivo(destino),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Bibliotecas section
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.library_books),
|
||||
const SizedBox(width: 8),
|
||||
const Text(
|
||||
'Bibliotecas',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () => _showBibliotecaDialog(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
BlocBuilder<EtiquetasCubit, EtiquetasState>(
|
||||
builder: (context, state) {
|
||||
if (state.bibliotecas.isEmpty) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Text('No hay bibliotecas configuradas'),
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
children: state.bibliotecas.map((bib) {
|
||||
final etiquetas = state.etiquetasPorBiblioteca[bib.id] ?? [];
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.folder),
|
||||
title: Text(bib.nombre),
|
||||
subtitle: Text(
|
||||
'${bib.url}${bib.endpoint}\n${etiquetas.length} etiquetas en cache',
|
||||
),
|
||||
isThreeLine: true,
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.sync),
|
||||
onPressed: () =>
|
||||
context.read<EtiquetasCubit>().syncBiblioteca(bib.id!),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// App info
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Row(
|
||||
children: [
|
||||
Icon(Icons.info_outline),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'Información',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const ListTile(
|
||||
title: Text('Packet'),
|
||||
subtitle: Text('v1.0.0'),
|
||||
leading: Icon(Icons.apps),
|
||||
),
|
||||
const ListTile(
|
||||
title: Text('Biblioteca HST'),
|
||||
subtitle: Text('tzrtech.org'),
|
||||
leading: Icon(Icons.link),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showDestinoDialog(BuildContext context) {
|
||||
final nombreController = TextEditingController();
|
||||
final urlController = TextEditingController();
|
||||
final hashController = TextEditingController();
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Nuevo Destino'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: nombreController,
|
||||
decoration: const InputDecoration(labelText: 'Nombre'),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: urlController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'URL',
|
||||
hintText: 'https://api.example.com',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: hashController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Llave (hash 64 chars)',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
if (nombreController.text.isNotEmpty &&
|
||||
urlController.text.isNotEmpty &&
|
||||
hashController.text.length == 64) {
|
||||
context.read<AppCubit>().addDestino(Destino(
|
||||
nombre: nombreController.text,
|
||||
url: urlController.text,
|
||||
hash: hashController.text,
|
||||
));
|
||||
Navigator.pop(ctx);
|
||||
}
|
||||
},
|
||||
child: const Text('Guardar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showBibliotecaDialog(BuildContext context) {
|
||||
final nombreController = TextEditingController();
|
||||
final urlController = TextEditingController();
|
||||
final endpointController = TextEditingController(text: '/api/tags');
|
||||
final configRepo = ConfigRepository();
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Nueva Biblioteca'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: nombreController,
|
||||
decoration: const InputDecoration(labelText: 'Nombre'),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: urlController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'URL',
|
||||
hintText: 'https://example.com',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: endpointController,
|
||||
decoration: const InputDecoration(labelText: 'Endpoint'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () async {
|
||||
if (nombreController.text.isNotEmpty && urlController.text.isNotEmpty) {
|
||||
await configRepo.insertBiblioteca(Biblioteca(
|
||||
nombre: nombreController.text,
|
||||
url: urlController.text,
|
||||
endpoint: endpointController.text,
|
||||
));
|
||||
if (ctx.mounted) {
|
||||
Navigator.pop(ctx);
|
||||
context.read<EtiquetasCubit>().init();
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const Text('Guardar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
235
lib/presentation/pages/etiquetas_page.dart
Normal file
235
lib/presentation/pages/etiquetas_page.dart
Normal file
@@ -0,0 +1,235 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import '../bloc/etiquetas/etiquetas_cubit.dart';
|
||||
import '../bloc/etiquetas/etiquetas_state.dart';
|
||||
import '../../core/utils/hash_utils.dart';
|
||||
|
||||
class EtiquetasPage extends StatefulWidget {
|
||||
const EtiquetasPage({super.key});
|
||||
|
||||
@override
|
||||
State<EtiquetasPage> createState() => _EtiquetasPageState();
|
||||
}
|
||||
|
||||
class _EtiquetasPageState extends State<EtiquetasPage> {
|
||||
final _hashController = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_hashController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<EtiquetasCubit, EtiquetasState>(
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
for (final bib in state.bibliotecas) {
|
||||
if (bib.id != null) {
|
||||
await context.read<EtiquetasCubit>().syncBiblioteca(bib.id!);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
// External hash input
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Añadir hash externo',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _hashController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Pegar URL o hash...',
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<EtiquetasCubit>()
|
||||
.addHashExterno(_hashController.text);
|
||||
_hashController.clear();
|
||||
},
|
||||
),
|
||||
),
|
||||
onSubmitted: (v) {
|
||||
context.read<EtiquetasCubit>().addHashExterno(v);
|
||||
_hashController.clear();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Selected tags
|
||||
if (state.seleccionadas.isNotEmpty) ...[
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'Seleccionadas (${state.seleccionadas.length})',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const Spacer(),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
context.read<EtiquetasCubit>().clearSeleccion(),
|
||||
child: const Text('Limpiar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: state.seleccionadas.map((hash) {
|
||||
final resolved = state.resolvedHashes[hash];
|
||||
return Chip(
|
||||
avatar: resolved?.imagenUrl != null
|
||||
? CircleAvatar(
|
||||
backgroundImage: CachedNetworkImageProvider(
|
||||
resolved!.imagenUrl!,
|
||||
),
|
||||
)
|
||||
: const CircleAvatar(child: Icon(Icons.tag, size: 16)),
|
||||
label: Text(resolved?.displayName ??
|
||||
HashUtils.truncateHash(hash)),
|
||||
onDeleted: () =>
|
||||
context.read<EtiquetasCubit>().removeEtiqueta(hash),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
// Bibliotecas
|
||||
...state.bibliotecas.map((biblioteca) {
|
||||
final etiquetas = state.etiquetasPorBiblioteca[biblioteca.id] ?? [];
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
biblioteca.nombre,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const Spacer(),
|
||||
if (etiquetas.isEmpty)
|
||||
TextButton.icon(
|
||||
onPressed: () => context
|
||||
.read<EtiquetasCubit>()
|
||||
.syncBiblioteca(biblioteca.id!),
|
||||
icon: const Icon(Icons.download, size: 18),
|
||||
label: const Text('Cargar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (etiquetas.isNotEmpty) ...[
|
||||
const SizedBox(height: 12),
|
||||
GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 4,
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisSpacing: 8,
|
||||
),
|
||||
itemCount: etiquetas.length,
|
||||
itemBuilder: (context, index) {
|
||||
final etiqueta = etiquetas[index];
|
||||
final isSelected = state.isSelected(etiqueta.hMaestro);
|
||||
return InkWell(
|
||||
onTap: () => context
|
||||
.read<EtiquetasCubit>()
|
||||
.toggleEtiqueta(etiqueta.hMaestro),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Colors.grey.shade300,
|
||||
width: isSelected ? 2 : 1,
|
||||
),
|
||||
color: isSelected
|
||||
? Theme.of(context)
|
||||
.colorScheme
|
||||
.primaryContainer
|
||||
.withOpacity(0.3)
|
||||
: null,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (etiqueta.imagenUrl != null)
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(4),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: etiqueta.imagenUrl!,
|
||||
fit: BoxFit.contain,
|
||||
placeholder: (_, __) =>
|
||||
const Icon(Icons.image),
|
||||
errorWidget: (_, __, ___) =>
|
||||
const Icon(Icons.tag),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
const Icon(Icons.tag),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(4),
|
||||
child: Text(
|
||||
etiqueta.ref ?? etiqueta.displayName,
|
||||
style: const TextStyle(fontSize: 10),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
141
lib/presentation/pages/packs_page.dart
Normal file
141
lib/presentation/pages/packs_page.dart
Normal file
@@ -0,0 +1,141 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../bloc/packs/packs_cubit.dart';
|
||||
import '../bloc/etiquetas/etiquetas_cubit.dart';
|
||||
import '../bloc/etiquetas/etiquetas_state.dart';
|
||||
|
||||
class PacksPage extends StatelessWidget {
|
||||
const PacksPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<PacksCubit, PacksState>(
|
||||
builder: (context, state) {
|
||||
if (state.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
body: state.packs.isEmpty
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.inventory_2_outlined,
|
||||
size: 64, color: Colors.grey.shade400),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'No hay packs',
|
||||
style: TextStyle(color: Colors.grey.shade600),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text('Crea uno seleccionando etiquetas'),
|
||||
],
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: state.packs.length,
|
||||
itemBuilder: (context, index) {
|
||||
final pack = state.packs[index];
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: Text(pack.icono, style: const TextStyle(fontSize: 24)),
|
||||
title: Text(pack.nombre),
|
||||
subtitle: Text('${pack.tagCount} etiquetas'),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.play_arrow),
|
||||
onPressed: () {
|
||||
context.read<EtiquetasCubit>().setSeleccionadas(pack.tags);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Pack "${pack.nombre}" aplicado'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
onPressed: () => _confirmDelete(context, pack),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
floatingActionButton: BlocBuilder<EtiquetasCubit, EtiquetasState>(
|
||||
builder: (context, etState) {
|
||||
if (etState.seleccionadas.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return FloatingActionButton.extended(
|
||||
onPressed: () => _showCreateDialog(context, etState.seleccionadas),
|
||||
icon: const Icon(Icons.add),
|
||||
label: Text('Crear (${etState.seleccionadas.length})'),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showCreateDialog(BuildContext context, List<String> tags) {
|
||||
final controller = TextEditingController();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Nuevo Pack'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nombre del pack',
|
||||
),
|
||||
autofocus: true,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
if (controller.text.isNotEmpty) {
|
||||
context.read<PacksCubit>().addPack(controller.text, tags);
|
||||
Navigator.pop(ctx);
|
||||
}
|
||||
},
|
||||
child: const Text('Crear'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _confirmDelete(BuildContext context, dynamic pack) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Eliminar pack'),
|
||||
content: Text('¿Eliminar "${pack.nombre}"?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
context.read<PacksCubit>().deletePack(pack.id);
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
child: const Text('Eliminar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
223
lib/presentation/pages/pendientes_page.dart
Normal file
223
lib/presentation/pages/pendientes_page.dart
Normal file
@@ -0,0 +1,223 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../bloc/pendientes/pendientes_cubit.dart';
|
||||
import '../bloc/app/app_cubit.dart';
|
||||
import '../bloc/app/app_state.dart';
|
||||
import '../../core/utils/hash_utils.dart';
|
||||
import '../../core/utils/retry_utils.dart';
|
||||
|
||||
class PendientesPage extends StatelessWidget {
|
||||
const PendientesPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<PendientesCubit, PendientesState>(
|
||||
builder: (context, state) {
|
||||
if (state.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
if (state.queueFull)
|
||||
Container(
|
||||
width: double.infinity,
|
||||
color: Theme.of(context).colorScheme.errorContainer,
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.warning,
|
||||
color: Theme.of(context).colorScheme.error),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Cola llena (20/20). Libera espacio para continuar.',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: state.pendientes.isEmpty
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.check_circle_outline,
|
||||
size: 64, color: Colors.green.shade400),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Sin pendientes',
|
||||
style: TextStyle(color: Colors.grey.shade600),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: RefreshIndicator(
|
||||
onRefresh: () => context.read<PendientesCubit>().load(),
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: state.pendientes.length,
|
||||
itemBuilder: (context, index) {
|
||||
final pendiente = state.pendientes[index];
|
||||
final dateFormat = DateFormat('HH:mm dd/MM');
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
pendiente.puedeReintentar
|
||||
? Icons.schedule
|
||||
: Icons.error,
|
||||
color: pendiente.puedeReintentar
|
||||
? Colors.orange
|
||||
: Colors.red,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
pendiente.titulo ?? 'Sin título',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text(
|
||||
HashUtils.truncateHash(
|
||||
pendiente.hash),
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 12,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
_InfoChip(
|
||||
icon: Icons.repeat,
|
||||
label: '${pendiente.intentos}/20',
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
if (pendiente.ultimoIntento != null)
|
||||
_InfoChip(
|
||||
icon: Icons.access_time,
|
||||
label: dateFormat
|
||||
.format(pendiente.ultimoIntento!),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
if (pendiente.proximoIntento != null)
|
||||
_InfoChip(
|
||||
icon: Icons.timer,
|
||||
label: RetryUtils.formatTimeRemaining(
|
||||
pendiente.proximoIntento!),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: () => context
|
||||
.read<PendientesCubit>()
|
||||
.eliminar(pendiente.hash),
|
||||
icon: const Icon(Icons.download),
|
||||
label: const Text('Recuperar'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
BlocBuilder<AppCubit, AppState>(
|
||||
builder: (context, appState) {
|
||||
return FilledButton.icon(
|
||||
onPressed: pendiente.puedeReintentar &&
|
||||
appState.destinoActivo !=
|
||||
null
|
||||
? () => context
|
||||
.read<PendientesCubit>()
|
||||
.reintentar(
|
||||
pendiente,
|
||||
appState.destinoActivo!,
|
||||
)
|
||||
: null,
|
||||
icon: const Icon(Icons.replay),
|
||||
label: const Text('Reintentar'),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: state.pendientes.isNotEmpty
|
||||
? BlocBuilder<AppCubit, AppState>(
|
||||
builder: (context, appState) {
|
||||
return FloatingActionButton.extended(
|
||||
onPressed: appState.destinoActivo != null
|
||||
? () => context
|
||||
.read<PendientesCubit>()
|
||||
.reintentarTodos(appState.destinoActivo!)
|
||||
: null,
|
||||
icon: const Icon(Icons.replay),
|
||||
label: const Text('Reintentar todos'),
|
||||
);
|
||||
},
|
||||
)
|
||||
: null,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _InfoChip extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
|
||||
const _InfoChip({required this.icon, required this.label});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade200,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 14, color: Colors.grey.shade600),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey.shade600),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user