feat: admin tools
This commit is contained in:
306
lib/src/views/admin.dart
Normal file
306
lib/src/views/admin.dart
Normal file
@@ -0,0 +1,306 @@
|
||||
// src/views/admin.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'rutas.dart';
|
||||
|
||||
class AdminView extends StatefulWidget {
|
||||
const AdminView({super.key});
|
||||
|
||||
@override
|
||||
State<AdminView> createState() => _AdminViewState();
|
||||
}
|
||||
|
||||
class _AdminViewState extends State<AdminView> {
|
||||
// Estado del camión
|
||||
bool _camionActivo = true;
|
||||
String _rutaActual = 'RUTA-01 - Zona Centro';
|
||||
String _horaActual = _getHoraActual();
|
||||
|
||||
// Controlador para minutos de retraso
|
||||
final TextEditingController _minutosController = TextEditingController();
|
||||
int _minutosRetraso = 0;
|
||||
|
||||
String _horaEstimadaOriginal = '8:30 AM';
|
||||
String _horaEstimadaActual = '8:30 AM';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_actualizarHora();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_minutosController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
static String _getHoraActual() {
|
||||
final now = DateTime.now();
|
||||
int hora = now.hour > 12 ? now.hour - 12 : now.hour;
|
||||
if (hora == 0) hora = 12;
|
||||
final minuto = now.minute.toString().padLeft(2, '0');
|
||||
final periodo = now.hour >= 12 ? 'PM' : 'AM';
|
||||
return '$hora:$minuto $periodo';
|
||||
}
|
||||
|
||||
void _actualizarHora() {
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_horaActual = _getHoraActual();
|
||||
});
|
||||
_actualizarHora();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _incrementarMinutos() {
|
||||
setState(() {
|
||||
_minutosRetraso++;
|
||||
_minutosController.text = _minutosRetraso.toString();
|
||||
});
|
||||
}
|
||||
|
||||
void _decrementarMinutos() {
|
||||
if (_minutosRetraso > 0) {
|
||||
setState(() {
|
||||
_minutosRetraso--;
|
||||
_minutosController.text = _minutosRetraso.toString();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _notificarRetraso() {
|
||||
if (_minutosRetraso == 0) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Ingresa los minutos de retraso'), backgroundColor: Colors.orange),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Retraso de $_minutosRetraso minutos notificado'),
|
||||
backgroundColor: Colors.orange,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _suspenderRuta() {
|
||||
setState(() {
|
||||
_camionActivo = !_camionActivo;
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(_camionActivo ? 'Ruta reactivada' : 'Ruta suspendida'),
|
||||
backgroundColor: _camionActivo ? Colors.green : Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold( // ← CAMBIADO: ahora usa Scaffold
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
backgroundColor: colorAzul,
|
||||
title: const Text(
|
||||
'Administración',
|
||||
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 28),
|
||||
),
|
||||
centerTitle: true,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.white, size: 30),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
children: [
|
||||
// Estado del camión
|
||||
_buildEstadoCamion(),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Información de ruta
|
||||
_buildInfoRuta(),
|
||||
const SizedBox(height: 30),
|
||||
|
||||
const Divider(thickness: 2, color: Colors.grey),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
const Text(
|
||||
'RETRASAR RUTA',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: colorAzul),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
// Selector de minutos
|
||||
_buildSelectorMinutos(),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
ElevatedButton(
|
||||
onPressed: _notificarRetraso,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.orange,
|
||||
minimumSize: const Size(double.infinity, 50),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
||||
),
|
||||
child: const Text(
|
||||
'NOTIFICAR RETRASO',
|
||||
style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Botón Suspender Ruta
|
||||
ElevatedButton(
|
||||
onPressed: _suspenderRuta,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _camionActivo ? Colors.red : Colors.green,
|
||||
minimumSize: const Size(double.infinity, 55),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
||||
),
|
||||
child: Text(
|
||||
_camionActivo ? 'SUSPENDER RUTA' : 'REACTIVAR RUTA',
|
||||
style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEstadoCamion() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.black, width: 4),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.local_shipping,
|
||||
size: 60,
|
||||
color: _camionActivo ? Colors.green : Colors.red,
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Estado del camión', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500)),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
_camionActivo ? 'ACTIVO' : 'INACTIVO',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _camionActivo ? Colors.green : Colors.red,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRuta() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.black, width: 4),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.route, size: 40),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Ruta actual', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
|
||||
Text(_rutaActual, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.access_time, size: 40),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Hora actual', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
|
||||
Text(_horaActual, style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold, color: colorAzul)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSelectorMinutos() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.black, width: 4),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: _decrementarMinutos,
|
||||
icon: const Icon(Icons.remove_circle, size: 50),
|
||||
color: colorAzul,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
SizedBox(
|
||||
width: 80,
|
||||
child: TextField(
|
||||
controller: _minutosController,
|
||||
keyboardType: TextInputType.number,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
hintText: '0',
|
||||
),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
if (value.isEmpty) {
|
||||
_minutosRetraso = 0;
|
||||
} else {
|
||||
_minutosRetraso = int.tryParse(value) ?? 0;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
IconButton(
|
||||
onPressed: _incrementarMinutos,
|
||||
icon: const Icon(Icons.add_circle, size: 50),
|
||||
color: colorAzul,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
const Text('min', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
// configuracion.dart
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'rutas.dart';
|
||||
import 'admin.dart';
|
||||
|
||||
class ConfiguracionView extends StatefulWidget {
|
||||
const ConfiguracionView({super.key});
|
||||
@@ -11,10 +12,13 @@ class ConfiguracionView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ConfiguracionViewState extends State<ConfiguracionView> {
|
||||
String selectedOption = '7 días'; // Valor por defecto
|
||||
String selectedOption = '7 días';
|
||||
bool _isLoading = true;
|
||||
|
||||
// Opciones del combobox
|
||||
// Para el botón secreto
|
||||
int _secretTapCount = 0;
|
||||
Timer? _resetTimer;
|
||||
|
||||
final List<String> opciones = [
|
||||
'Cada día',
|
||||
'Cada 3 días',
|
||||
@@ -22,7 +26,6 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
||||
'Cada quincena',
|
||||
];
|
||||
|
||||
// Mapa para mostrar valores más amigables
|
||||
final Map<String, String> opcionesMap = {
|
||||
'Cada día': '1 día',
|
||||
'Cada 3 días': '3 días',
|
||||
@@ -36,7 +39,12 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
||||
_cargarPreferencia();
|
||||
}
|
||||
|
||||
// Cargar la preferencia guardada
|
||||
@override
|
||||
void dispose() {
|
||||
_resetTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _cargarPreferencia() async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
@@ -49,20 +57,17 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
print('Error al cargar preferencia: $e');
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Guardar la preferencia
|
||||
Future<void> _guardarPreferencia(String value) async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('notificacion_frecuencia', value);
|
||||
|
||||
// Mostrar mensaje de confirmación
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
@@ -77,7 +82,6 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
||||
}
|
||||
}
|
||||
|
||||
// Mostrar diálogo con opciones
|
||||
void _mostrarSelector() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
@@ -137,6 +141,41 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
||||
);
|
||||
}
|
||||
|
||||
// 🔥 BOTÓN SECRETO - Tocar el ícono 5 veces
|
||||
void _onSecretTap() {
|
||||
_secretTapCount++;
|
||||
|
||||
// Cancelar el reset anterior si existe
|
||||
_resetTimer?.cancel();
|
||||
|
||||
// Resetear después de 1.5 segundos si no completa los 5 taps
|
||||
_resetTimer = Timer(const Duration(milliseconds: 1500), () {
|
||||
_secretTapCount = 0;
|
||||
print('🔐 Contador reiniciado');
|
||||
});
|
||||
|
||||
print('🔐 Taps secretos: $_secretTapCount/5');
|
||||
|
||||
if (_secretTapCount >= 5) {
|
||||
_resetTimer?.cancel();
|
||||
_secretTapCount = 0;
|
||||
|
||||
// Navegar a Admin
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const AdminView()),
|
||||
);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('🔐 Modo administrador activado'),
|
||||
backgroundColor: Colors.green,
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
@@ -144,7 +183,6 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
// AppBar personalizado
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
|
||||
@@ -165,7 +203,6 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
// Contenido
|
||||
Expanded(
|
||||
child: _isLoading
|
||||
? const Center(
|
||||
@@ -188,7 +225,11 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.notifications_active_outlined, size: 60),
|
||||
// 🔥 BOTÓN SECRETO - Solo el ícono responde a los taps
|
||||
GestureDetector(
|
||||
onTap: _onSecretTap,
|
||||
child: const Icon(Icons.notifications_active_outlined, size: 60),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
selectedOption,
|
||||
@@ -204,7 +245,6 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// Información adicional
|
||||
Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
@@ -227,6 +267,18 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[200],
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Text(
|
||||
'👆 Toca el ícono de la campana 5 veces rápido para Admin',
|
||||
style: TextStyle(fontSize: 11, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user