Compare commits
8 Commits
feature/re
...
feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
473b871ed5 | ||
|
|
6667ec4c5d | ||
|
|
c0b88fea86 | ||
|
|
88532b43e7 | ||
|
|
1f2d162c34 | ||
|
|
e10bb97afb | ||
|
|
36c04582f3 | ||
|
|
2d56d6de0d |
@@ -1,10 +1,12 @@
|
|||||||
// main.dart
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'src/views/rutas.dart';
|
import 'src/views/rutas.dart';
|
||||||
import 'src/views/main_screen.dart';
|
import 'src/views/login.dart';
|
||||||
import 'src/views/login.dart'; // Importar LoginView
|
import 'src/views/home_screen.dart';
|
||||||
|
import 'src/services/notification_service.dart'; // ← AGREGAR
|
||||||
|
|
||||||
void main() {
|
void main() async { // ← CAMBIAR a async
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
await NotificationService.initialize(); // ← AGREGAR await
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,10 +62,10 @@ class RegistroView extends StatelessWidget {
|
|||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15))
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15))
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// Navegar a MainScreen (app principal)
|
// ✅ Navegar a HomeScreen (única barra de navegación)
|
||||||
Navigator.pushReplacement(
|
Navigator.pushReplacement(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => const MainScreen()),
|
MaterialPageRoute(builder: (context) => const HomeScreen()),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text('Registrar', style: TextStyle(color: Colors.white, fontSize: 18)),
|
child: const Text('Registrar', style: TextStyle(color: Colors.white, fontSize: 18)),
|
||||||
|
|||||||
40
lib/src/data/horarios_data.dart
Normal file
40
lib/src/data/horarios_data.dart
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
// src/data/horarios_data.dart
|
||||||
|
class HorarioInfo {
|
||||||
|
final String colonia;
|
||||||
|
final String routeId;
|
||||||
|
final String horarioEstimado;
|
||||||
|
|
||||||
|
HorarioInfo({
|
||||||
|
required this.colonia,
|
||||||
|
required this.routeId,
|
||||||
|
required this.horarioEstimado,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<HorarioInfo> horariosBase = [
|
||||||
|
HorarioInfo(colonia: 'Zona Centro', routeId: 'RUTA-01', horarioEstimado: '06:30'),
|
||||||
|
HorarioInfo(colonia: 'Las Arboledas', routeId: 'RUTA-01', horarioEstimado: '07:00'),
|
||||||
|
HorarioInfo(colonia: 'Trojes', routeId: 'RUTA-13', horarioEstimado: '06:40'),
|
||||||
|
HorarioInfo(colonia: 'San Juanico', routeId: 'RUTA-03', horarioEstimado: '06:45'),
|
||||||
|
HorarioInfo(colonia: 'Los Olivos', routeId: 'RUTA-04', horarioEstimado: '07:00'),
|
||||||
|
HorarioInfo(colonia: 'Rancho Seco', routeId: 'RUTA-05', horarioEstimado: '14:15'),
|
||||||
|
HorarioInfo(colonia: 'Las Insurgentes', routeId: 'RUTA-12', horarioEstimado: '06:35'),
|
||||||
|
];
|
||||||
|
|
||||||
|
// Obtener horario por nombre de colonia
|
||||||
|
String getHorarioByColonia(String colonia) {
|
||||||
|
final found = horariosBase.firstWhere(
|
||||||
|
(h) => h.colonia.toLowerCase() == colonia.toLowerCase(),
|
||||||
|
orElse: () => HorarioInfo(colonia: '', routeId: '', horarioEstimado: '08:00'),
|
||||||
|
);
|
||||||
|
return found.horarioEstimado;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtener routeId por nombre de colonia
|
||||||
|
String getRouteIdByColonia(String colonia) {
|
||||||
|
final found = horariosBase.firstWhere(
|
||||||
|
(h) => h.colonia.toLowerCase() == colonia.toLowerCase(),
|
||||||
|
orElse: () => HorarioInfo(colonia: '', routeId: 'RUTA-00', horarioEstimado: '08:00'),
|
||||||
|
);
|
||||||
|
return found.routeId;
|
||||||
|
}
|
||||||
@@ -1,44 +1,60 @@
|
|||||||
|
// src/models/domicilio_model.dart
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import '../data/horarios_data.dart';
|
||||||
|
|
||||||
class Domicilio {
|
class Domicilio {
|
||||||
|
final String id;
|
||||||
final String nombre;
|
final String nombre;
|
||||||
final String colonia;
|
final String colonia;
|
||||||
final String calle;
|
final String calle;
|
||||||
final String numero;
|
final String numero;
|
||||||
final String id;
|
final double latitud;
|
||||||
|
final double longitud;
|
||||||
|
final String horarioEstimado;
|
||||||
|
final String routeId;
|
||||||
|
|
||||||
Domicilio({
|
Domicilio({
|
||||||
|
required this.id,
|
||||||
required this.nombre,
|
required this.nombre,
|
||||||
required this.colonia,
|
required this.colonia,
|
||||||
required this.calle,
|
required this.calle,
|
||||||
required this.numero,
|
required this.numero,
|
||||||
required this.id,
|
required this.latitud,
|
||||||
|
required this.longitud,
|
||||||
|
required this.horarioEstimado,
|
||||||
|
required this.routeId,
|
||||||
});
|
});
|
||||||
|
|
||||||
String get direccionCompleta => '$colonia, $calle $numero';
|
String get direccionCompleta => '$colonia, $calle $numero';
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
|
'id': id,
|
||||||
'nombre': nombre,
|
'nombre': nombre,
|
||||||
'colonia': colonia,
|
'colonia': colonia,
|
||||||
'calle': calle,
|
'calle': calle,
|
||||||
'numero': numero,
|
'numero': numero,
|
||||||
'id': id,
|
'latitud': latitud,
|
||||||
|
'longitud': longitud,
|
||||||
|
'horarioEstimado': horarioEstimado,
|
||||||
|
'routeId': routeId,
|
||||||
};
|
};
|
||||||
|
|
||||||
factory Domicilio.fromJson(Map<String, dynamic> json) {
|
factory Domicilio.fromJson(Map<String, dynamic> json) {
|
||||||
return Domicilio(
|
return Domicilio(
|
||||||
|
id: json['id'],
|
||||||
nombre: json['nombre'],
|
nombre: json['nombre'],
|
||||||
colonia: json['colonia'],
|
colonia: json['colonia'],
|
||||||
calle: json['calle'],
|
calle: json['calle'],
|
||||||
numero: json['numero'],
|
numero: json['numero'],
|
||||||
id: json['id'],
|
latitud: (json['latitud'] as num).toDouble(),
|
||||||
|
longitud: (json['longitud'] as num).toDouble(),
|
||||||
|
horarioEstimado: json['horarioEstimado'] ?? getHorarioByColonia(json['colonia']),
|
||||||
|
routeId: json['routeId'] ?? getRouteIdByColonia(json['colonia']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String encode(List<Domicilio> domicilios) {
|
static String encode(List<Domicilio> domicilios) {
|
||||||
return json.encode(
|
return json.encode(domicilios.map((d) => d.toJson()).toList());
|
||||||
domicilios.map((d) => d.toJson()).toList(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<Domicilio> decode(String domiciliosString) {
|
static List<Domicilio> decode(String domiciliosString) {
|
||||||
|
|||||||
72
lib/src/services/geolocation_service.dart
Normal file
72
lib/src/services/geolocation_service.dart
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
// src/services/geolocation_service.dart
|
||||||
|
import 'package:geolocator/geolocator.dart';
|
||||||
|
|
||||||
|
class SimplePosition {
|
||||||
|
final double latitude;
|
||||||
|
final double longitude;
|
||||||
|
final DateTime timestamp;
|
||||||
|
|
||||||
|
SimplePosition({
|
||||||
|
required this.latitude,
|
||||||
|
required this.longitude,
|
||||||
|
required this.timestamp,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class GeolocationService {
|
||||||
|
static Future<bool> isLocationServiceEnabled() async {
|
||||||
|
return await Geolocator.isLocationServiceEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<LocationPermission> checkPermission() async {
|
||||||
|
return await Geolocator.checkPermission();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<LocationPermission> requestPermission() async {
|
||||||
|
return await Geolocator.requestPermission();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<bool> hasPermission() async {
|
||||||
|
LocationPermission permission = await Geolocator.checkPermission();
|
||||||
|
return permission == LocationPermission.always ||
|
||||||
|
permission == LocationPermission.whileInUse;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<SimplePosition?> getCurrentLocation() async {
|
||||||
|
try {
|
||||||
|
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||||
|
if (!serviceEnabled) return null;
|
||||||
|
|
||||||
|
LocationPermission permission = await Geolocator.checkPermission();
|
||||||
|
if (permission == LocationPermission.denied) {
|
||||||
|
permission = await Geolocator.requestPermission();
|
||||||
|
if (permission == LocationPermission.denied) return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (permission == LocationPermission.deniedForever) return null;
|
||||||
|
|
||||||
|
Position position = await Geolocator.getCurrentPosition(
|
||||||
|
desiredAccuracy: LocationAccuracy.low,
|
||||||
|
timeLimit: const Duration(seconds: 5),
|
||||||
|
);
|
||||||
|
|
||||||
|
return SimplePosition(
|
||||||
|
latitude: position.latitude,
|
||||||
|
longitude: position.longitude,
|
||||||
|
timestamp: position.timestamp,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print('Error: $e');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<SimplePosition?> getCurrentLocationWithRetry({int maxRetries = 2}) async {
|
||||||
|
for (int i = 0; i < maxRetries; i++) {
|
||||||
|
final position = await getCurrentLocation();
|
||||||
|
if (position != null) return position;
|
||||||
|
if (i < maxRetries - 1) await Future.delayed(const Duration(seconds: 1));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
43
lib/src/services/notification_service.dart
Normal file
43
lib/src/services/notification_service.dart
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
// src/services/notification_service.dart
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
|
|
||||||
|
class NotificationService {
|
||||||
|
static final FlutterLocalNotificationsPlugin _notifications = FlutterLocalNotificationsPlugin();
|
||||||
|
|
||||||
|
static Future<void> initialize() async {
|
||||||
|
const AndroidInitializationSettings androidSettings = AndroidInitializationSettings('@mipmap/ic_launcher');
|
||||||
|
const DarwinInitializationSettings iosSettings = DarwinInitializationSettings();
|
||||||
|
const InitializationSettings settings = InitializationSettings(
|
||||||
|
android: androidSettings,
|
||||||
|
iOS: iosSettings,
|
||||||
|
);
|
||||||
|
await _notifications.initialize(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> showNotification({
|
||||||
|
required String title,
|
||||||
|
required String body,
|
||||||
|
String? payload,
|
||||||
|
}) async {
|
||||||
|
const AndroidNotificationDetails androidDetails = AndroidNotificationDetails(
|
||||||
|
'recoleccion_channel',
|
||||||
|
'Notificaciones de Recolección',
|
||||||
|
channelDescription: 'Notificaciones sobre el estado de la recolección',
|
||||||
|
importance: Importance.high,
|
||||||
|
priority: Priority.high,
|
||||||
|
);
|
||||||
|
const DarwinNotificationDetails iosDetails = DarwinNotificationDetails();
|
||||||
|
const NotificationDetails details = NotificationDetails(
|
||||||
|
android: androidDetails,
|
||||||
|
iOS: iosDetails,
|
||||||
|
);
|
||||||
|
await _notifications.show(
|
||||||
|
DateTime.now().millisecond,
|
||||||
|
title,
|
||||||
|
body,
|
||||||
|
details,
|
||||||
|
payload: payload,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
233
lib/src/views/admin.dart
Normal file
233
lib/src/views/admin.dart
Normal file
@@ -0,0 +1,233 @@
|
|||||||
|
// src/views/admin.dart
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'rutas.dart';
|
||||||
|
import '../services/notification_service.dart';
|
||||||
|
|
||||||
|
class AdminView extends StatefulWidget {
|
||||||
|
const AdminView({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<AdminView> createState() => _AdminViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AdminViewState extends State<AdminView> {
|
||||||
|
bool _camionActivo = true;
|
||||||
|
String _rutaActual = 'RUTA-01 - Zona Centro';
|
||||||
|
String _horaActual = _getHoraActual();
|
||||||
|
final TextEditingController _minutosController = TextEditingController();
|
||||||
|
int _minutosRetraso = 0;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_actualizarHora();
|
||||||
|
_cargarEstado();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_minutosController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _cargarEstado() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
setState(() {
|
||||||
|
_camionActivo = !(prefs.getBool('ruta_suspendida') ?? false);
|
||||||
|
_minutosRetraso = prefs.getInt('retraso_minutos') ?? 0;
|
||||||
|
_minutosController.text = _minutosRetraso.toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _notificarRetraso() async {
|
||||||
|
if (_minutosRetraso == 0) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Ingresa los minutos de retraso'), backgroundColor: Colors.orange),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setInt('retraso_minutos', _minutosRetraso);
|
||||||
|
|
||||||
|
await NotificationService.showNotification(
|
||||||
|
title: '⏰ Retraso en la ruta',
|
||||||
|
body: 'El camión ha sufrido un retraso de $_minutosRetraso minutos en todas las rutas.',
|
||||||
|
);
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('Retraso de $_minutosRetraso minutos aplicado'), backgroundColor: Colors.orange),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _suspenderRuta() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
final nuevaSuspension = !_camionActivo;
|
||||||
|
|
||||||
|
await prefs.setBool('ruta_suspendida', nuevaSuspension);
|
||||||
|
|
||||||
|
if (nuevaSuspension) {
|
||||||
|
await NotificationService.showNotification(
|
||||||
|
title: '⛔ Ruta suspendida',
|
||||||
|
body: 'El servicio de recolección ha sido suspendido por hoy.',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await prefs.remove('retraso_minutos');
|
||||||
|
await NotificationService.showNotification(
|
||||||
|
title: '✅ Ruta reactivada',
|
||||||
|
body: 'El servicio de recolección ha sido reactivado.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_camionActivo = !_camionActivo;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return 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: [
|
||||||
|
_buildEstadoCamion(),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
_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),
|
||||||
|
_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),
|
||||||
|
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(() { _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,9 @@
|
|||||||
// configuracion.dart
|
import 'dart:async';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'rutas.dart';
|
import 'rutas.dart';
|
||||||
|
import 'admin.dart';
|
||||||
|
import '../services/notification_service.dart';
|
||||||
|
|
||||||
class ConfiguracionView extends StatefulWidget {
|
class ConfiguracionView extends StatefulWidget {
|
||||||
const ConfiguracionView({super.key});
|
const ConfiguracionView({super.key});
|
||||||
@@ -11,10 +13,17 @@ class ConfiguracionView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ConfiguracionViewState extends State<ConfiguracionView> {
|
class _ConfiguracionViewState extends State<ConfiguracionView> {
|
||||||
String selectedOption = '7 días'; // Valor por defecto
|
String selectedOption = '7 días';
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
|
|
||||||
// Opciones del combobox
|
// Para el botón secreto de Admin
|
||||||
|
int _secretTapCount = 0;
|
||||||
|
Timer? _resetTimer;
|
||||||
|
|
||||||
|
// Para el botón secreto de notificación de prueba (3 taps en el texto de ayuda)
|
||||||
|
int _testNotificationTapCount = 0;
|
||||||
|
Timer? _testResetTimer;
|
||||||
|
|
||||||
final List<String> opciones = [
|
final List<String> opciones = [
|
||||||
'Cada día',
|
'Cada día',
|
||||||
'Cada 3 días',
|
'Cada 3 días',
|
||||||
@@ -22,7 +31,6 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
|||||||
'Cada quincena',
|
'Cada quincena',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Mapa para mostrar valores más amigables
|
|
||||||
final Map<String, String> opcionesMap = {
|
final Map<String, String> opcionesMap = {
|
||||||
'Cada día': '1 día',
|
'Cada día': '1 día',
|
||||||
'Cada 3 días': '3 días',
|
'Cada 3 días': '3 días',
|
||||||
@@ -36,7 +44,13 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
|||||||
_cargarPreferencia();
|
_cargarPreferencia();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cargar la preferencia guardada
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_resetTimer?.cancel();
|
||||||
|
_testResetTimer?.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _cargarPreferencia() async {
|
Future<void> _cargarPreferencia() async {
|
||||||
try {
|
try {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
@@ -49,20 +63,17 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
|||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error al cargar preferencia: $e');
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Guardar la preferencia
|
|
||||||
Future<void> _guardarPreferencia(String value) async {
|
Future<void> _guardarPreferencia(String value) async {
|
||||||
try {
|
try {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
await prefs.setString('notificacion_frecuencia', value);
|
await prefs.setString('notificacion_frecuencia', value);
|
||||||
|
|
||||||
// Mostrar mensaje de confirmación
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
@@ -77,7 +88,6 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mostrar diálogo con opciones
|
|
||||||
void _mostrarSelector() {
|
void _mostrarSelector() {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -137,6 +147,69 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 🔥 BOTÓN SECRETO 1: Tocar el ícono 5 veces para Admin
|
||||||
|
void _onSecretTap() {
|
||||||
|
_secretTapCount++;
|
||||||
|
|
||||||
|
_resetTimer?.cancel();
|
||||||
|
_resetTimer = Timer(const Duration(milliseconds: 1500), () {
|
||||||
|
_secretTapCount = 0;
|
||||||
|
print('🔐 Contador Admin reiniciado');
|
||||||
|
});
|
||||||
|
|
||||||
|
print('🔐 Taps Admin: $_secretTapCount/5');
|
||||||
|
|
||||||
|
if (_secretTapCount >= 5) {
|
||||||
|
_resetTimer?.cancel();
|
||||||
|
_secretTapCount = 0;
|
||||||
|
|
||||||
|
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),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔥 BOTÓN SECRETO 2: Tocar el texto de ayuda 3 veces para notificación de prueba
|
||||||
|
void _onTestNotificationTap() {
|
||||||
|
_testNotificationTapCount++;
|
||||||
|
|
||||||
|
_testResetTimer?.cancel();
|
||||||
|
_testResetTimer = Timer(const Duration(milliseconds: 1500), () {
|
||||||
|
_testNotificationTapCount = 0;
|
||||||
|
print('🔐 Contador Notificacion reiniciado');
|
||||||
|
});
|
||||||
|
|
||||||
|
print('🔐 Taps Notificacion: $_testNotificationTapCount/3');
|
||||||
|
|
||||||
|
if (_testNotificationTapCount >= 3) {
|
||||||
|
_testResetTimer?.cancel();
|
||||||
|
_testNotificationTapCount = 0;
|
||||||
|
|
||||||
|
// Enviar notificación de prueba
|
||||||
|
NotificationService.showNotification(
|
||||||
|
title: '🔔 Notificación de prueba',
|
||||||
|
body: 'Esta es una notificación de prueba. ¡Tu app funciona correctamente!',
|
||||||
|
);
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('🔔 Notificación de prueba enviada'),
|
||||||
|
backgroundColor: Colors.blue,
|
||||||
|
duration: Duration(seconds: 2),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
@@ -144,7 +217,6 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
|||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
// AppBar personalizado
|
|
||||||
Container(
|
Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
|
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
|
||||||
@@ -165,7 +237,6 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
|||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// Contenido
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: _isLoading
|
child: _isLoading
|
||||||
? const Center(
|
? const Center(
|
||||||
@@ -188,7 +259,11 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
|||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.notifications_active_outlined, size: 60),
|
// 🔥 BOTÓN SECRETO ADMIN (5 taps)
|
||||||
|
GestureDetector(
|
||||||
|
onTap: _onSecretTap,
|
||||||
|
child: const Icon(Icons.notifications_active_outlined, size: 60),
|
||||||
|
),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
Text(
|
Text(
|
||||||
selectedOption,
|
selectedOption,
|
||||||
@@ -204,7 +279,6 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
// Información adicional
|
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.all(15),
|
padding: const EdgeInsets.all(15),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -227,6 +301,39 @@ class _ConfiguracionViewState extends State<ConfiguracionView> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
// 🔥 BOTÓN SECRETO NOTIFICACIÓN DE PRUEBA (3 taps en este texto)
|
||||||
|
GestureDetector(
|
||||||
|
onTap: _onTestNotificationTap,
|
||||||
|
child: 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 para Admin',
|
||||||
|
style: TextStyle(fontSize: 11, color: Colors.grey),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
// Indicador del segundo botón secreto
|
||||||
|
GestureDetector(
|
||||||
|
onTap: _onTestNotificationTap,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(6),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.blue.withOpacity(0.1),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
'🔔 Toca este texto 3 veces para notificación de prueba',
|
||||||
|
style: TextStyle(fontSize: 10, color: Colors.blue),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
// domicilios.dart
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:geolocator/geolocator.dart';
|
||||||
import 'rutas.dart';
|
import 'rutas.dart';
|
||||||
import '../models/domicilio_model.dart';
|
import '../models/domicilio_model.dart';
|
||||||
import 'dart:math';
|
import '../services/geolocation_service.dart';
|
||||||
|
import '../data/horarios_data.dart';
|
||||||
|
|
||||||
class DomiciliosView extends StatefulWidget {
|
class DomiciliosView extends StatefulWidget {
|
||||||
const DomiciliosView({super.key});
|
const DomiciliosView({super.key});
|
||||||
@@ -15,8 +16,8 @@ class DomiciliosView extends StatefulWidget {
|
|||||||
class _DomiciliosViewState extends State<DomiciliosView> {
|
class _DomiciliosViewState extends State<DomiciliosView> {
|
||||||
List<Domicilio> domicilios = [];
|
List<Domicilio> domicilios = [];
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
|
bool _isLoadingLocation = false;
|
||||||
|
|
||||||
// Controladores para el formulario
|
|
||||||
final TextEditingController nombreController = TextEditingController();
|
final TextEditingController nombreController = TextEditingController();
|
||||||
final TextEditingController coloniaController = TextEditingController();
|
final TextEditingController coloniaController = TextEditingController();
|
||||||
final TextEditingController calleController = TextEditingController();
|
final TextEditingController calleController = TextEditingController();
|
||||||
@@ -37,43 +38,121 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cargar domicilios guardados
|
|
||||||
Future<void> _cargarDomicilios() async {
|
Future<void> _cargarDomicilios() async {
|
||||||
try {
|
try {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
final String? domiciliosString = prefs.getString('domicilios');
|
final String? domiciliosString = prefs.getString('domicilios');
|
||||||
|
|
||||||
|
setState(() {
|
||||||
if (domiciliosString != null && domiciliosString.isNotEmpty) {
|
if (domiciliosString != null && domiciliosString.isNotEmpty) {
|
||||||
setState(() {
|
|
||||||
domicilios = Domicilio.decode(domiciliosString);
|
domicilios = Domicilio.decode(domiciliosString);
|
||||||
_isLoading = false;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setState(() {
|
|
||||||
_isLoading = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error al cargar domicilios: $e');
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Guardar domicilios en SharedPreferences
|
|
||||||
Future<void> _guardarDomicilios() async {
|
Future<void> _guardarDomicilios() async {
|
||||||
try {
|
try {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
final String domiciliosString = Domicilio.encode(domicilios);
|
final String domiciliosString = Domicilio.encode(domicilios);
|
||||||
await prefs.setString('domicilios', domiciliosString);
|
await prefs.setString('domicilios', domiciliosString);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error al guardar domicilios: $e');
|
print('Error al guardar: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _mostrarDialogoAgregar() {
|
Future<bool> _showLocationPermissionDialog() async {
|
||||||
// Limpiar controladores
|
if (await GeolocationService.hasPermission()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final result = await showDialog<bool>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
title: const Text('Permiso de ubicacion'),
|
||||||
|
content: const Text(
|
||||||
|
'Necesitamos acceder a tu ubicacion para asignar tu domicilio a la ruta correcta.',
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context, false),
|
||||||
|
child: const Text('Cancelar'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context, true),
|
||||||
|
child: const Text('Aceptar', style: TextStyle(color: colorAzul)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result == true) {
|
||||||
|
LocationPermission newPermission = await GeolocationService.requestPermission();
|
||||||
|
return newPermission == LocationPermission.always ||
|
||||||
|
newPermission == LocationPermission.whileInUse;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _obtenerUbicacionYAgregar() async {
|
||||||
|
setState(() {
|
||||||
|
_isLoadingLocation = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
final serviceEnabled = await GeolocationService.isLocationServiceEnabled();
|
||||||
|
if (!serviceEnabled) {
|
||||||
|
setState(() {
|
||||||
|
_isLoadingLocation = false;
|
||||||
|
});
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('Activa el GPS para agregar un domicilio'),
|
||||||
|
backgroundColor: Colors.orange,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final hasPermission = await _showLocationPermissionDialog();
|
||||||
|
if (!hasPermission) {
|
||||||
|
setState(() {
|
||||||
|
_isLoadingLocation = false;
|
||||||
|
});
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('Necesitamos tu ubicacion'),
|
||||||
|
backgroundColor: Colors.orange,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final simplePosition = await GeolocationService.getCurrentLocation();
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_isLoadingLocation = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (simplePosition == null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('No se pudo obtener tu ubicacion.'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_mostrarDialogoAgregarConUbicacion(simplePosition.latitude, simplePosition.longitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _mostrarDialogoAgregarConUbicacion(double lat, double lng) {
|
||||||
nombreController.clear();
|
nombreController.clear();
|
||||||
coloniaController.clear();
|
coloniaController.clear();
|
||||||
calleController.clear();
|
calleController.clear();
|
||||||
@@ -90,86 +169,53 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
// Título
|
const Text('Anadir domicilio', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold, color: colorAzul)),
|
||||||
const Text(
|
const SizedBox(height: 10),
|
||||||
'Añadir domicilio',
|
Container(
|
||||||
style: TextStyle(
|
padding: const EdgeInsets.all(12),
|
||||||
fontSize: 24,
|
decoration: BoxDecoration(color: Colors.green.withOpacity(0.1), borderRadius: BorderRadius.circular(12)),
|
||||||
fontWeight: FontWeight.bold,
|
child: Row(
|
||||||
color: colorAzul,
|
children: [
|
||||||
|
Icon(Icons.location_on, color: Colors.green[700], size: 24),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text('Ubicacion obtenida', style: TextStyle(fontSize: 12, color: Colors.green[700])),
|
||||||
|
Text('Lat: ${lat.toStringAsFixed(6)}'),
|
||||||
|
Text('Lng: ${lng.toStringAsFixed(6)}'),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
],
|
||||||
// Campo: Nombre del domicilio
|
),
|
||||||
_buildCampoTexto(
|
|
||||||
controller: nombreController,
|
|
||||||
hint: 'Nombre del domicilio',
|
|
||||||
icon: Icons.home_outlined,
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 15),
|
const SizedBox(height: 15),
|
||||||
// Campo: Colonia
|
_buildCampoTexto(controller: nombreController, hint: 'Nombre del domicilio', icon: Icons.home_outlined),
|
||||||
_buildCampoTexto(
|
|
||||||
controller: coloniaController,
|
|
||||||
hint: 'Colonia',
|
|
||||||
icon: Icons.location_city_outlined,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 15),
|
const SizedBox(height: 15),
|
||||||
// Campo: Calle
|
_buildCampoTexto(controller: coloniaController, hint: 'Colonia', icon: Icons.location_city_outlined),
|
||||||
_buildCampoTexto(
|
|
||||||
controller: calleController,
|
|
||||||
hint: 'Calle',
|
|
||||||
icon: Icons.streetview,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 15),
|
const SizedBox(height: 15),
|
||||||
// Campo: Número
|
_buildCampoTexto(controller: calleController, hint: 'Calle', icon: Icons.streetview),
|
||||||
_buildCampoTexto(
|
const SizedBox(height: 15),
|
||||||
controller: numeroController,
|
_buildCampoTexto(controller: numeroController, hint: 'Numero', icon: Icons.numbers, keyboardType: TextInputType.number),
|
||||||
hint: 'Número',
|
|
||||||
icon: Icons.numbers,
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 25),
|
const SizedBox(height: 25),
|
||||||
// Botones
|
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: [
|
||||||
// Botón Cancelar
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: OutlinedButton(
|
child: OutlinedButton(
|
||||||
style: OutlinedButton.styleFrom(
|
style: OutlinedButton.styleFrom(side: BorderSide(color: colorAzul, width: 2), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15))),
|
||||||
side: BorderSide(color: colorAzul, width: 2),
|
onPressed: () => Navigator.pop(context),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
child: const Text('Cancelar', style: TextStyle(color: colorAzul)),
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(15),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
child: const Text(
|
|
||||||
'Cancelar',
|
|
||||||
style: TextStyle(fontSize: 16, color: colorAzul),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 15),
|
const SizedBox(width: 15),
|
||||||
// Botón Agregar
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(backgroundColor: colorAzul, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15))),
|
||||||
backgroundColor: colorAzul,
|
onPressed: () => _agregarDomicilio(latitud: lat, longitud: lng),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
child: const Text('Agregar', style: TextStyle(color: Colors.white)),
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(15),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
_agregarDomicilio();
|
|
||||||
},
|
|
||||||
child: const Text(
|
|
||||||
'Agregar',
|
|
||||||
style: TextStyle(fontSize: 16, color: Colors.white),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -194,167 +240,99 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
|||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: hint,
|
hintText: hint,
|
||||||
prefixIcon: Icon(icon, color: colorAzul),
|
prefixIcon: Icon(icon, color: colorAzul),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(borderRadius: BorderRadius.circular(15)),
|
||||||
borderRadius: BorderRadius.circular(15),
|
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(15), borderSide: BorderSide(color: colorAzul.withOpacity(0.5))),
|
||||||
borderSide: const BorderSide(color: colorAzul),
|
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(15), borderSide: const BorderSide(color: colorAzul, width: 2)),
|
||||||
),
|
|
||||||
enabledBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(15),
|
|
||||||
borderSide: BorderSide(color: colorAzul.withOpacity(0.5)),
|
|
||||||
),
|
|
||||||
focusedBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(15),
|
|
||||||
borderSide: const BorderSide(color: colorAzul, width: 2),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _agregarDomicilio() async {
|
void _agregarDomicilio({required double latitud, required double longitud}) async {
|
||||||
// Validar que todos los campos estén llenos
|
if (nombreController.text.trim().isEmpty ||
|
||||||
if (nombreController.text.isEmpty ||
|
coloniaController.text.trim().isEmpty ||
|
||||||
coloniaController.text.isEmpty ||
|
calleController.text.trim().isEmpty ||
|
||||||
calleController.text.isEmpty ||
|
numeroController.text.trim().isEmpty) {
|
||||||
numeroController.text.isEmpty) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(content: Text('Llena todos los campos'), backgroundColor: Colors.red),
|
||||||
content: Text('Por favor, llena todos los campos'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crear nuevo domicilio con ID único
|
final horario = getHorarioByColonia(coloniaController.text.trim());
|
||||||
|
final routeId = getRouteIdByColonia(coloniaController.text.trim());
|
||||||
|
|
||||||
final nuevoDomicilio = Domicilio(
|
final nuevoDomicilio = Domicilio(
|
||||||
nombre: nombreController.text,
|
id: DateTime.now().millisecondsSinceEpoch.toString(),
|
||||||
colonia: coloniaController.text,
|
nombre: nombreController.text.trim(),
|
||||||
calle: calleController.text,
|
colonia: coloniaController.text.trim(),
|
||||||
numero: numeroController.text,
|
calle: calleController.text.trim(),
|
||||||
id: DateTime.now().millisecondsSinceEpoch.toString(), // ID único
|
numero: numeroController.text.trim(),
|
||||||
|
latitud: latitud,
|
||||||
|
longitud: longitud,
|
||||||
|
horarioEstimado: horario,
|
||||||
|
routeId: routeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Agregar a la lista
|
|
||||||
setState(() {
|
setState(() {
|
||||||
domicilios.add(nuevoDomicilio);
|
domicilios.add(nuevoDomicilio);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Guardar en SharedPreferences
|
|
||||||
await _guardarDomicilios();
|
await _guardarDomicilios();
|
||||||
|
|
||||||
// Cerrar el diálogo
|
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
|
|
||||||
// Mostrar mensaje de éxito
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(content: Text('Domicilio agregado'), backgroundColor: colorAzul),
|
||||||
content: Text('Domicilio "${nombreController.text}" agregado'),
|
|
||||||
backgroundColor: colorAzul,
|
|
||||||
duration: const Duration(seconds: 2),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _eliminarDomicilio(int index) async {
|
void _eliminarDomicilio(int index) async {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (context) => AlertDialog(
|
||||||
return AlertDialog(
|
|
||||||
title: const Text('Eliminar domicilio'),
|
title: const Text('Eliminar domicilio'),
|
||||||
content: Text('¿Deseas eliminar "${domicilios[index].nombre}"?'),
|
content: Text('Eliminar "${domicilios[index].nombre}"?'),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Cancelar')),
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
child: const Text('Cancelar'),
|
|
||||||
),
|
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
setState(() {
|
setState(() => domicilios.removeAt(index));
|
||||||
domicilios.removeAt(index);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Guardar cambios en SharedPreferences
|
|
||||||
await _guardarDomicilios();
|
await _guardarDomicilios();
|
||||||
|
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(
|
|
||||||
content: Text('Domicilio eliminado'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
duration: Duration(seconds: 2),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
child: const Text('Eliminar', style: TextStyle(color: Colors.red)),
|
child: const Text('Eliminar', style: TextStyle(color: Colors.red)),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
),
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return SafeArea(
|
||||||
color: Colors.white,
|
|
||||||
child: SafeArea(
|
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
// AppBar personalizado
|
|
||||||
Container(
|
Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
|
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
color: colorAzul,
|
color: colorAzul,
|
||||||
borderRadius: BorderRadius.only(
|
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20)),
|
||||||
bottomLeft: Radius.circular(20),
|
|
||||||
bottomRight: Radius.circular(20),
|
|
||||||
),
|
),
|
||||||
|
child: const Text('Domicilios', style: TextStyle(color: Colors.white, fontSize: 28, fontWeight: FontWeight.bold), textAlign: TextAlign.center),
|
||||||
),
|
),
|
||||||
child: const Text(
|
|
||||||
'Domicilios',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 28,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// Contenido
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: _isLoading
|
child: _isLoading
|
||||||
? const Center(
|
? const Center(child: CircularProgressIndicator(color: colorAzul))
|
||||||
child: CircularProgressIndicator(
|
|
||||||
color: colorAzul,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: domicilios.isEmpty
|
: domicilios.isEmpty
|
||||||
? Center(
|
? Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(Icons.home_outlined, size: 100, color: Colors.grey.withOpacity(0.5)),
|
||||||
Icons.home_outlined,
|
|
||||||
size: 100,
|
|
||||||
color: Colors.grey.withOpacity(0.5),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Text(
|
Text('No hay domicilios', style: TextStyle(fontSize: 18, color: Colors.grey.withOpacity(0.7))),
|
||||||
'No hay domicilios agregados',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
color: Colors.grey.withOpacity(0.7),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Text(
|
Text('Toca el boton + para agregar', style: TextStyle(fontSize: 14, color: Colors.grey.withOpacity(0.5))),
|
||||||
'Toca el botón + para agregar',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Colors.grey.withOpacity(0.5),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -362,15 +340,12 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
|||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(20),
|
||||||
itemCount: domicilios.length,
|
itemCount: domicilios.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final domicilio = domicilios[index];
|
final d = domicilios[index];
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 20),
|
padding: const EdgeInsets.only(bottom: 20),
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(15),
|
padding: const EdgeInsets.all(15),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 4), borderRadius: BorderRadius.circular(25)),
|
||||||
border: Border.all(color: Colors.black, width: 4),
|
|
||||||
borderRadius: BorderRadius.circular(25),
|
|
||||||
),
|
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.home_outlined, size: 60),
|
const Icon(Icons.home_outlined, size: 60),
|
||||||
@@ -379,28 +354,13 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(d.nombre, style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
|
||||||
domicilio.nombre,
|
Text(d.direccionCompleta, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||||
style: const TextStyle(
|
Text('${d.latitud.toStringAsFixed(4)}, ${d.longitud.toStringAsFixed(4)}', style: TextStyle(fontSize: 12, color: Colors.grey[600])),
|
||||||
fontSize: 22,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
domicilio.direccionCompleta,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(onPressed: () => _eliminarDomicilio(index), icon: const Icon(Icons.delete_outline, size: 40), color: Colors.red),
|
||||||
onPressed: () => _eliminarDomicilio(index),
|
|
||||||
icon: const Icon(Icons.delete_outline, size: 40),
|
|
||||||
color: Colors.red,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -408,25 +368,17 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// Botón flotante de agregar
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(20),
|
||||||
child: GestureDetector(
|
child: _isLoadingLocation
|
||||||
onTap: _mostrarDialogoAgregar,
|
? Container(width: double.infinity, height: 100, decoration: BoxDecoration(color: colorAzul, borderRadius: BorderRadius.circular(20)), child: const Center(child: CircularProgressIndicator(color: Colors.white)))
|
||||||
child: Container(
|
: GestureDetector(
|
||||||
width: double.infinity,
|
onTap: _obtenerUbicacionYAgregar,
|
||||||
height: 100,
|
child: Container(width: double.infinity, height: 100, decoration: BoxDecoration(color: colorAzul, borderRadius: BorderRadius.circular(20)), child: const Icon(Icons.add, color: Colors.white, size: 80)),
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: colorAzul,
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
),
|
|
||||||
child: const Icon(Icons.add, color: Colors.white, size: 80),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
42
lib/src/views/home_screen.dart
Normal file
42
lib/src/views/home_screen.dart
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// home_screen.dart
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'domicilios.dart';
|
||||||
|
import 'horarios.dart';
|
||||||
|
import 'configuracion.dart';
|
||||||
|
import 'rutas.dart';
|
||||||
|
import 'nav_bar.dart';
|
||||||
|
|
||||||
|
class HomeScreen extends StatefulWidget {
|
||||||
|
const HomeScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<HomeScreen> createState() => _HomeScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HomeScreenState extends State<HomeScreen> {
|
||||||
|
int _currentIndex = 0; // 0: Domicilios, 1: Rutas, 2: Configuración
|
||||||
|
|
||||||
|
final List<Widget> _paginas = const [
|
||||||
|
DomiciliosView(),
|
||||||
|
HorariosView(),
|
||||||
|
ConfiguracionView(),
|
||||||
|
];
|
||||||
|
|
||||||
|
void _onNavBarTap(int index) {
|
||||||
|
setState(() {
|
||||||
|
_currentIndex = index;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
body: _paginas[_currentIndex],
|
||||||
|
bottomNavigationBar: CustomNavBar(
|
||||||
|
currentIndex: _currentIndex,
|
||||||
|
onTap: _onNavBarTap,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,117 @@
|
|||||||
|
// horarios.dart - Versión actualizada
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'rutas.dart';
|
import 'rutas.dart';
|
||||||
|
import '../models/domicilio_model.dart';
|
||||||
|
import 'mapa_expandible.dart';
|
||||||
|
import '../services/notification_service.dart';
|
||||||
|
|
||||||
class HorariosView extends StatelessWidget {
|
class HorariosView extends StatefulWidget {
|
||||||
const HorariosView({super.key});
|
const HorariosView({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
State<HorariosView> createState() => _HorariosViewState();
|
||||||
final List<Map<String, String>> rutas = List.generate(
|
}
|
||||||
6,
|
|
||||||
(index) => {
|
|
||||||
'colonia': 'Colonia ${index + 1}',
|
|
||||||
'ruta': 'Ruta ${index + 1}',
|
|
||||||
'horario': '${8 + (index % 3)}:${30 * (index % 2)} ${index < 3 ? 'AM' : 'PM'}',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
|
class _HorariosViewState extends State<HorariosView> {
|
||||||
|
List<Domicilio> domicilios = [];
|
||||||
|
bool _isLoading = true;
|
||||||
|
Timer? _timer;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_cargarDomicilios();
|
||||||
|
_iniciarVerificacionHorarios();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_timer?.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _iniciarVerificacionHorarios() {
|
||||||
|
_timer = Timer.periodic(const Duration(minutes: 1), (timer) {
|
||||||
|
_verificarHorarios();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _verificarHorarios() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
final suspensionActiva = prefs.getBool('ruta_suspendida') ?? false;
|
||||||
|
final retrasoMinutos = prefs.getInt('retraso_minutos') ?? 0;
|
||||||
|
|
||||||
|
if (suspensionActiva) return;
|
||||||
|
|
||||||
|
final ahora = DateTime.now();
|
||||||
|
final horaActual = ahora.hour * 60 + ahora.minute;
|
||||||
|
|
||||||
|
for (var domicilio in domicilios) {
|
||||||
|
final partes = domicilio.horarioEstimado.split(':');
|
||||||
|
int hora = int.parse(partes[0]);
|
||||||
|
int minuto = int.parse(partes[1]);
|
||||||
|
|
||||||
|
// Aplicar retraso
|
||||||
|
int horaConRetraso = hora;
|
||||||
|
int minutoConRetraso = minuto + retrasoMinutos;
|
||||||
|
if (minutoConRetraso >= 60) {
|
||||||
|
horaConRetraso += minutoConRetraso ~/ 60;
|
||||||
|
minutoConRetraso = minutoConRetraso % 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
final horarioMinutos = horaConRetraso * 60 + minutoConRetraso;
|
||||||
|
|
||||||
|
// Si la hora actual está dentro del rango (5 minutos antes y durante)
|
||||||
|
if (horaActual >= horarioMinutos - 5 && horaActual <= horarioMinutos + 15) {
|
||||||
|
// Verificar si ya se notificó esta hora
|
||||||
|
final lastNotification = prefs.getString('last_notification_${domicilio.id}');
|
||||||
|
final todayKey = '${DateTime.now().day}-${DateTime.now().month}-${DateTime.now().year}';
|
||||||
|
|
||||||
|
if (lastNotification != todayKey) {
|
||||||
|
await prefs.setString('last_notification_${domicilio.id}', todayKey);
|
||||||
|
await NotificationService.showNotification(
|
||||||
|
title: '🚛 El camión está cerca',
|
||||||
|
body: 'El camión de recolección está por llegar a ${domicilio.colonia}. ¡Prepara tu basura!',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _cargarDomicilios() async {
|
||||||
|
try {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
final String? domiciliosString = prefs.getString('domicilios');
|
||||||
|
final retrasoMinutos = prefs.getInt('retraso_minutos') ?? 0;
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
if (domiciliosString != null && domiciliosString.isNotEmpty) {
|
||||||
|
domicilios = Domicilio.decode(domiciliosString);
|
||||||
|
}
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String _obtenerHorarioConRetraso(int index) {
|
||||||
|
final prefs = SharedPreferences.getInstance();
|
||||||
|
final retraso = prefs is int ? prefs : 0;
|
||||||
|
// Simplificado - en producción usar Future
|
||||||
|
return domicilios[index].horarioEstimado;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
// AppBar personalizado
|
|
||||||
Container(
|
Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
|
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
|
||||||
@@ -32,42 +123,31 @@ class HorariosView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: const Text(
|
child: const Text(
|
||||||
'Horarios',
|
'Mis Rutas',
|
||||||
style: TextStyle(
|
style: TextStyle(color: Colors.white, fontSize: 32, fontWeight: FontWeight.bold),
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 32,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// Lista de horarios
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: _isLoading
|
||||||
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 24),
|
? const Center(child: CircularProgressIndicator(color: colorAzul))
|
||||||
itemCount: rutas.length,
|
: domicilios.isEmpty
|
||||||
itemBuilder: (context, index) {
|
? Center(
|
||||||
final item = rutas[index];
|
child: Column(
|
||||||
return Padding(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
children: [
|
||||||
Column(
|
Icon(Icons.location_on_outlined, size: 100, color: Colors.grey.withOpacity(0.5)),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
const SizedBox(height: 20),
|
||||||
children: [
|
Text('No hay domicilios agregados', style: TextStyle(fontSize: 18, color: Colors.grey.withOpacity(0.7))),
|
||||||
Text(item['colonia']!,
|
const SizedBox(height: 10),
|
||||||
style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
|
Text('Agrega domicilios desde la pestaña Domicilios', style: TextStyle(fontSize: 14, color: Colors.grey.withOpacity(0.5)), textAlign: TextAlign.center),
|
||||||
Text(item['ruta']!,
|
|
||||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Text(item['horario']!,
|
)
|
||||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
|
: ListView.builder(
|
||||||
],
|
padding: const EdgeInsets.all(20),
|
||||||
),
|
itemCount: domicilios.length,
|
||||||
);
|
itemBuilder: (context, index) => _buildDomicilioCard(domicilios[index], index),
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -75,4 +155,103 @@ class HorariosView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildDomicilioCard(Domicilio domicilio, int index) {
|
||||||
|
return FutureBuilder<SharedPreferences>(
|
||||||
|
future: SharedPreferences.getInstance(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
int retraso = 0;
|
||||||
|
bool suspendida = false;
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
retraso = snapshot.data!.getInt('retraso_minutos') ?? 0;
|
||||||
|
suspendida = snapshot.data!.getBool('ruta_suspendida') ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String horarioMostrar = domicilio.horarioEstimado;
|
||||||
|
if (retraso > 0 && !suspendida) {
|
||||||
|
final partes = domicilio.horarioEstimado.split(':');
|
||||||
|
int hora = int.parse(partes[0]);
|
||||||
|
int minuto = int.parse(partes[1]);
|
||||||
|
minuto += retraso;
|
||||||
|
if (minuto >= 60) {
|
||||||
|
hora += minuto ~/ 60;
|
||||||
|
minuto = minuto % 60;
|
||||||
|
}
|
||||||
|
horarioMostrar = '${hora.toString().padLeft(2, '0')}:${minuto.toString().padLeft(2, '0')} (retraso $retraso min)';
|
||||||
|
} else if (suspendida) {
|
||||||
|
horarioMostrar = 'SUSPENDIDA';
|
||||||
|
}
|
||||||
|
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 20),
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: Colors.black, width: 4),
|
||||||
|
borderRadius: BorderRadius.circular(25),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(15),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.home_outlined, size: 60),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(domicilio.nombre, style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(domicilio.direccionCompleta, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500)),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text('📍 ${domicilio.latitud.toStringAsFixed(4)}, ${domicilio.longitud.toStringAsFixed(4)}', style: TextStyle(fontSize: 12, color: Colors.grey[600])),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: suspendida ? Colors.red.withOpacity(0.2) : colorAzul.withOpacity(0.1),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.access_time, color: suspendida ? Colors.red : colorAzul, size: 20),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
suspendida ? 'RUTA SUSPENDIDA' : 'Horario: $horarioMostrar',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: suspendida ? Colors.red : colorAzul,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
MapaExpandible(
|
||||||
|
latitud: domicilio.latitud,
|
||||||
|
longitud: domicilio.longitud,
|
||||||
|
nombreDomicilio: domicilio.nombre,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
|
// login.dart - cambiar MainScreen por HomeScreen
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'rutas.dart';
|
import 'rutas.dart';
|
||||||
import 'main_screen.dart';
|
import 'home_screen.dart'; // ← Importar HomeScreen
|
||||||
|
|
||||||
class LoginView extends StatelessWidget {
|
class LoginView extends StatelessWidget {
|
||||||
const LoginView({super.key});
|
const LoginView({super.key});
|
||||||
@@ -27,16 +28,12 @@ class LoginView extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.all(30.0),
|
padding: const EdgeInsets.all(30.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
// Campo de Correo
|
|
||||||
_buildInput(Icons.email_outlined, 'Correo electrónico', obscureText: false),
|
_buildInput(Icons.email_outlined, 'Correo electrónico', obscureText: false),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
// Campo de Contraseña
|
|
||||||
_buildInput(Icons.lock_outline, 'Contraseña', obscureText: true),
|
_buildInput(Icons.lock_outline, 'Contraseña', obscureText: true),
|
||||||
const SizedBox(height: 50),
|
const SizedBox(height: 50),
|
||||||
// Botones
|
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
// Botón Iniciar Sesión
|
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: colorAzul,
|
backgroundColor: colorAzul,
|
||||||
@@ -44,9 +41,10 @@ class LoginView extends StatelessWidget {
|
|||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
// ✅ Navegar a HomeScreen
|
||||||
Navigator.pushReplacement(
|
Navigator.pushReplacement(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => const MainScreen()),
|
MaterialPageRoute(builder: (context) => const HomeScreen()),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text(
|
child: const Text(
|
||||||
@@ -55,7 +53,6 @@ class LoginView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
// Botón Crear Cuenta
|
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
style: OutlinedButton.styleFrom(
|
style: OutlinedButton.styleFrom(
|
||||||
minimumSize: const Size(double.infinity, 55),
|
minimumSize: const Size(double.infinity, 55),
|
||||||
|
|||||||
138
lib/src/views/mapa_expandible.dart
Normal file
138
lib/src/views/mapa_expandible.dart
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
// src/views/mapa_expandible.dart
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
import 'rutas.dart';
|
||||||
|
|
||||||
|
class MapaExpandible extends StatefulWidget {
|
||||||
|
final double latitud;
|
||||||
|
final double longitud;
|
||||||
|
final String nombreDomicilio;
|
||||||
|
|
||||||
|
const MapaExpandible({
|
||||||
|
super.key,
|
||||||
|
required this.latitud,
|
||||||
|
required this.longitud,
|
||||||
|
required this.nombreDomicilio,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MapaExpandible> createState() => _MapaExpandibleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MapaExpandibleState extends State<MapaExpandible> {
|
||||||
|
bool _isExpanded = false;
|
||||||
|
|
||||||
|
bool get _isValidLatLng {
|
||||||
|
final lat = widget.latitud;
|
||||||
|
final lng = widget.longitud;
|
||||||
|
return lat.isFinite && lng.isFinite && lat != 0 && lng != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _abrirGoogleMaps() async {
|
||||||
|
final url = 'https://www.google.com/maps?q=${widget.latitud},${widget.longitud}&z=15';
|
||||||
|
try {
|
||||||
|
if (await canLaunch(url)) {
|
||||||
|
await launch(url);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('No se pudo abrir el mapa'), backgroundColor: Colors.red),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (!_isValidLatLng) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey[200],
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
child: const Text('Ubicación no disponible', style: TextStyle(fontSize: 12)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
_isExpanded = !_isExpanded;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey[200],
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
_isExpanded ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down,
|
||||||
|
color: colorAzul,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
_isExpanded ? 'Ocultar mapa' : 'Ver mapa',
|
||||||
|
style: TextStyle(color: colorAzul, fontSize: 12, fontWeight: FontWeight.w500),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (_isExpanded)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 12),
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: _abrirGoogleMaps,
|
||||||
|
child: Container(
|
||||||
|
width: 200, // Ancho fijo en lugar de infinity
|
||||||
|
height: 160,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(15),
|
||||||
|
border: Border.all(color: colorAzul.withOpacity(0.3), width: 1),
|
||||||
|
color: Colors.grey[100],
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.map, size: 40, color: colorAzul),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'Ver en Google Maps',
|
||||||
|
style: TextStyle(color: colorAzul, fontWeight: FontWeight.bold, fontSize: 14),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(
|
||||||
|
'${widget.latitud.toStringAsFixed(4)}, ${widget.longitud.toStringAsFixed(4)}',
|
||||||
|
style: TextStyle(fontSize: 11, color: Colors.grey[600]),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 3),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: colorAzul,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
'Tocar para abrir',
|
||||||
|
style: TextStyle(color: Colors.white, fontSize: 11),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user