Compare commits
11 Commits
master
...
vista_dire
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af5d086cf9 | ||
|
|
f6463307da | ||
|
|
211e14cef5 | ||
|
|
218ad84991 | ||
|
|
649752a6a4 | ||
|
|
7d07cc101d | ||
|
|
1709a51ecc | ||
|
|
6638f471e1 | ||
|
|
c560fb09fb | ||
|
|
6ae45fd371 | ||
|
|
c91d1f298e |
13
.vscode/settings.json
vendored
Normal file
13
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"yaml.customTags": [
|
||||||
|
"!upload scalar",
|
||||||
|
"!remove scalar",
|
||||||
|
"!keep scalar",
|
||||||
|
"!erase scalar",
|
||||||
|
"!jwt scalar"
|
||||||
|
],
|
||||||
|
"yaml.schemas": {
|
||||||
|
"https://raw.githubusercontent.com/doanthuanthanh88/testapi6/main/schema.json": "*.yaml"
|
||||||
|
},
|
||||||
|
"cmake.sourceDirectory": "C:/Users/Mendez/Documents/Practicas de programacion/Proyecto-Hackathon (ITC)/hackathon-sfc-a9a4cee23109413188ee35ceac01dc07/windows"
|
||||||
|
}
|
||||||
38
lib/core/network/mysql_service.dart
Normal file
38
lib/core/network/mysql_service.dart
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import 'package:mysql_client/mysql_client.dart';
|
||||||
|
|
||||||
|
class MySqlService {
|
||||||
|
MySQLConnection? _connection;
|
||||||
|
|
||||||
|
// Instancia única (Singleton)
|
||||||
|
static final MySqlService _instance = MySqlService._internal();
|
||||||
|
factory MySqlService() => _instance;
|
||||||
|
MySqlService._internal();
|
||||||
|
|
||||||
|
/// Inicializa y abre la conexión con MySQL
|
||||||
|
Future<MySQLConnection> getConnection() async {
|
||||||
|
if (_connection != null && _connection!.connected) {
|
||||||
|
return _connection!;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ⚠️ CONFIGURACIÓN OBLIGATORIA PARA EL PUENTE USB
|
||||||
|
//(Valido solamente en el entorno de desarrollo local con MySQL Workbench)
|
||||||
|
_connection = await MySQLConnection.createConnection(
|
||||||
|
host: '127.0.0.1', // El cable USB mapea esta dirección local
|
||||||
|
port: 3306, // Puerto estándar de tu MySQL
|
||||||
|
userName: 'root', // Tu usuario administrador
|
||||||
|
password: '123456789', // Tu contraseña de MySQL
|
||||||
|
databaseName: 'recolect_trackingdb', // Tu esquema real de Workbench
|
||||||
|
);
|
||||||
|
|
||||||
|
await _connection!.connect();
|
||||||
|
return _connection!;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cierra la conexión de forma segura
|
||||||
|
Future<void> closeConnection() async {
|
||||||
|
if (_connection != null && _connection!.connected) {
|
||||||
|
await _connection!.close();
|
||||||
|
_connection = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +1,24 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter_application_1/features/auth/presentation/screens/register_screen.dart';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
import '../../features/auth/presentation/bloc/auth_bloc.dart';
|
import '../../features/auth/presentation/bloc/auth_bloc.dart';
|
||||||
import '../../features/auth/presentation/bloc/auth_state.dart';
|
import '../../features/auth/presentation/bloc/auth_state.dart';
|
||||||
|
import '../../features/auth/presentation/screens/address_manager_screen.dart';
|
||||||
import '../../features/auth/presentation/screens/login_screen.dart';
|
import '../../features/auth/presentation/screens/login_screen.dart';
|
||||||
|
import '../../features/auth/presentation/screens/register_screen.dart';
|
||||||
import '../../features/auth/presentation/screens/home_screen_placeholder.dart';
|
import '../../features/auth/presentation/screens/home_screen_placeholder.dart';
|
||||||
|
|
||||||
/// Rutas nombradas de la aplicación.
|
/// Rutas nombradas de la aplicación.
|
||||||
abstract final class AppRoutes {
|
abstract final class AppRoutes {
|
||||||
static const String splash = '/';
|
static const String splash = '/';
|
||||||
static const String login = '/login';
|
static const String login = '/login';
|
||||||
|
static const String register = '/register';
|
||||||
static const String home = '/home';
|
static const String home = '/home';
|
||||||
|
static const String addresses = '/addresses';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configuración central de navegación con go_router.
|
/// Configuración central de navegación con go_router.
|
||||||
///
|
|
||||||
/// La redirección basada en estado de autenticación garantiza que
|
|
||||||
/// rutas protegidas sean inaccesibles sin sesión válida.
|
|
||||||
GoRouter createRouter(AuthBloc authBloc) {
|
GoRouter createRouter(AuthBloc authBloc) {
|
||||||
return GoRouter(
|
return GoRouter(
|
||||||
initialLocation: AppRoutes.splash,
|
initialLocation: AppRoutes.splash,
|
||||||
@@ -36,15 +35,24 @@ GoRouter createRouter(AuthBloc authBloc) {
|
|||||||
return currentLocation == AppRoutes.splash ? null : AppRoutes.splash;
|
return currentLocation == AppRoutes.splash ? null : AppRoutes.splash;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si no está autenticado, ir a login.
|
// 📍 SOLUCIÓN HACKATÓN: Si la app intenta ir al Home o a Direcciones,
|
||||||
if (!isAuthenticated) {
|
// ignoramos el candado de seguridad para no rebotar al login.
|
||||||
return currentLocation == AppRoutes.login ? null : AppRoutes.login;
|
if (currentLocation == AppRoutes.home ||
|
||||||
|
currentLocation == AppRoutes.addresses) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si está autenticado y en splash o login, ir a home.
|
// Permitir acceso a rutas públicas sin estar autenticado
|
||||||
if (isAuthenticated &&
|
final publicRoutes = [AppRoutes.login, AppRoutes.register];
|
||||||
(currentLocation == AppRoutes.login ||
|
final isPublicRoute = publicRoutes.contains(currentLocation);
|
||||||
currentLocation == AppRoutes.splash)) {
|
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
// Si no está autenticado y no está en una ruta pública, mandarlo a login
|
||||||
|
return isPublicRoute ? null : AppRoutes.login;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si está autenticado e intenta ir a login o registro, mandarlo a home
|
||||||
|
if (isAuthenticated && isPublicRoute) {
|
||||||
return AppRoutes.home;
|
return AppRoutes.home;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,21 +68,17 @@ GoRouter createRouter(AuthBloc authBloc) {
|
|||||||
builder: (context, state) => const LoginScreen(),
|
builder: (context, state) => const LoginScreen(),
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: AppRoutes.home,
|
path: AppRoutes.register,
|
||||||
builder: (context, state) => const HomeScreenPlaceholder(),
|
|
||||||
),
|
|
||||||
// 📍 Agrega el import arriba si te lo pide:
|
|
||||||
// import 'package:flutter_application_1/features/auth/presentation/screens/register_screen.dart';
|
|
||||||
|
|
||||||
GoRoute(
|
|
||||||
path: AppRoutes.home,
|
|
||||||
builder: (context, state) => const HomeScreenPlaceholder(),
|
|
||||||
),
|
|
||||||
// 📍 CORRECCIÓN: Usamos la constante oficial del proyecto en lugar del texto a mano
|
|
||||||
GoRoute(
|
|
||||||
path: '/register', // 📍 CORRECCIÓN: Texto plano limpio entre comillas
|
|
||||||
builder: (context, state) => const RegisterScreen(),
|
builder: (context, state) => const RegisterScreen(),
|
||||||
), // GoRoute
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: AppRoutes.home,
|
||||||
|
builder: (context, state) => const HomeScreenPlaceholder(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: AppRoutes.addresses,
|
||||||
|
builder: (context, state) => const AddressManagerScreen(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -91,11 +95,7 @@ class _SplashScreen extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const Icon(
|
const Icon(Icons.recycling_rounded, size: 72, color: Colors.white),
|
||||||
Icons.recycling_rounded,
|
|
||||||
size: 72,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
Text(
|
Text(
|
||||||
'WasteNotify',
|
'WasteNotify',
|
||||||
@@ -117,7 +117,6 @@ class _SplashScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Notificador que conecta el estado del BLoC con go_router.
|
/// Notificador que conecta el estado del BLoC con go_router.
|
||||||
/// Permite que el router reaccione automáticamente a cambios de sesión.
|
|
||||||
class GoRouterAuthNotifier extends ChangeNotifier {
|
class GoRouterAuthNotifier extends ChangeNotifier {
|
||||||
final AuthBloc _authBloc;
|
final AuthBloc _authBloc;
|
||||||
late final StreamSubscription<AuthState> _subscription;
|
late final StreamSubscription<AuthState> _subscription;
|
||||||
|
|||||||
13
lib/core/security/password_hasher.dart
Normal file
13
lib/core/security/password_hasher.dart
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:crypto/crypto.dart';
|
||||||
|
|
||||||
|
class PasswordHasher {
|
||||||
|
static const String _salt = 'waste-notify-local-salt-v1';
|
||||||
|
|
||||||
|
static String hash(String password) {
|
||||||
|
final normalized = password.trim();
|
||||||
|
final bytes = utf8.encode('$_salt:$normalized');
|
||||||
|
return sha256.convert(bytes).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,7 +55,7 @@ abstract final class AppTheme {
|
|||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
elevation: 3,
|
elevation: 3,
|
||||||
shadowColor: leafGreen.withOpacity(0.4),
|
shadowColor: leafGreen.withValues(alpha: 0.4),
|
||||||
textStyle: const TextStyle(
|
textStyle: const TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.w700,
|
fontWeight: FontWeight.w700,
|
||||||
@@ -89,12 +89,12 @@ abstract final class AppTheme {
|
|||||||
borderSide: const BorderSide(color: errorRed, width: 2),
|
borderSide: const BorderSide(color: errorRed, width: 2),
|
||||||
),
|
),
|
||||||
labelStyle: const TextStyle(color: midGray),
|
labelStyle: const TextStyle(color: midGray),
|
||||||
hintStyle: TextStyle(color: midGray.withOpacity(0.7)),
|
hintStyle: TextStyle(color: midGray.withValues(alpha: 0.7)),
|
||||||
),
|
),
|
||||||
cardTheme: CardThemeData(
|
cardTheme: CardThemeData(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
elevation: 2,
|
elevation: 2,
|
||||||
shadowColor: Colors.black.withOpacity(0.08),
|
shadowColor: Colors.black.withValues(alpha: 0.08),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -0,0 +1,309 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
|
import '../../../../core/router/app_router.dart';
|
||||||
|
|
||||||
|
class AddressManagerScreen extends StatefulWidget {
|
||||||
|
const AddressManagerScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<AddressManagerScreen> createState() => _AddressManagerScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AddressManagerScreenState extends State<AddressManagerScreen> {
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
final _aliasController = TextEditingController();
|
||||||
|
final _streetController = TextEditingController();
|
||||||
|
final _coloniaController = TextEditingController();
|
||||||
|
final Map<String, _RouteInfo> _routeCatalog = {
|
||||||
|
'zona centro': _RouteInfo(routeId: 'RUTA-01', schedule: 'Matutino (06:30 - 07:15)'),
|
||||||
|
'las arboledas': _RouteInfo(routeId: 'RUTA-01', schedule: 'Matutino (07:00 - 07:30)'),
|
||||||
|
'trojes': _RouteInfo(routeId: 'RUTA-13', schedule: 'Matutino (06:40 - 07:10)'),
|
||||||
|
'san juanico': _RouteInfo(routeId: 'RUTA-03', schedule: 'Matutino (06:45 - 07:15)'),
|
||||||
|
'los olivos': _RouteInfo(routeId: 'RUTA-04', schedule: 'Matutino (07:00 - 07:40)'),
|
||||||
|
'rancho seco': _RouteInfo(routeId: 'RUTA-05', schedule: 'Vespertino (14:15 - 15:00)'),
|
||||||
|
'las insurgentes': _RouteInfo(routeId: 'RUTA-12', schedule: 'Matutino (06:35 - 07:10)'),
|
||||||
|
};
|
||||||
|
|
||||||
|
final List<_SavedAddress> _savedAddresses = [
|
||||||
|
_SavedAddress(
|
||||||
|
alias: 'Casa',
|
||||||
|
street: 'Av. Siempre Viva 123',
|
||||||
|
colonia: 'Zona Centro',
|
||||||
|
routeId: 'RUTA-01',
|
||||||
|
schedule: 'Matutino (06:30 - 07:15)',
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_aliasController.dispose();
|
||||||
|
_streetController.dispose();
|
||||||
|
_coloniaController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _saveAddress() {
|
||||||
|
if (!_formKey.currentState!.validate()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final colonia = _coloniaController.text.trim();
|
||||||
|
final routeInfo = _routeCatalog[colonia.toLowerCase()];
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_savedAddresses.insert(
|
||||||
|
0,
|
||||||
|
_SavedAddress(
|
||||||
|
alias: _aliasController.text.trim(),
|
||||||
|
street: _streetController.text.trim(),
|
||||||
|
colonia: colonia,
|
||||||
|
routeId: routeInfo?.routeId ?? 'Ruta no encontrada',
|
||||||
|
schedule: routeInfo?.schedule ?? 'Horario no disponible',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
_aliasController.clear();
|
||||||
|
_streetController.clear();
|
||||||
|
_coloniaController.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Dirección guardada correctamente')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: const Color(0xFFF5F7F5),
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
elevation: 0,
|
||||||
|
title: const Text(
|
||||||
|
'Mis direcciones',
|
||||||
|
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
||||||
|
onPressed: () => context.go(AppRoutes.home),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
bottomNavigationBar: NavigationBar(
|
||||||
|
selectedIndex: 1,
|
||||||
|
onDestinationSelected: (index) {
|
||||||
|
if (index == 0) {
|
||||||
|
context.go(AppRoutes.home);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
destinations: const [
|
||||||
|
NavigationDestination(
|
||||||
|
icon: Icon(Icons.home_outlined),
|
||||||
|
selectedIcon: Icon(Icons.home),
|
||||||
|
label: 'Inicio',
|
||||||
|
),
|
||||||
|
NavigationDestination(
|
||||||
|
icon: Icon(Icons.location_on_outlined),
|
||||||
|
selectedIcon: Icon(Icons.location_on),
|
||||||
|
label: 'Direcciones',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: ListView(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
gradient: const LinearGradient(
|
||||||
|
colors: [Color(0xFF1B5E20), Color(0xFF2E7D32)],
|
||||||
|
begin: Alignment.topLeft,
|
||||||
|
end: Alignment.bottomRight,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(24),
|
||||||
|
),
|
||||||
|
child: const Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.place, color: Colors.white, size: 34),
|
||||||
|
SizedBox(height: 12),
|
||||||
|
Text(
|
||||||
|
'Agrega tus direcciones',
|
||||||
|
style: TextStyle(color: Colors.white, fontSize: 22, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'Guarda uno o varios domicilios para relacionarlos con tus rutas de recolección.',
|
||||||
|
style: TextStyle(color: Colors.white70, fontSize: 14, height: 1.4),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Card(
|
||||||
|
elevation: 1,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(18),
|
||||||
|
child: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
TextFormField(
|
||||||
|
controller: _aliasController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Alias',
|
||||||
|
prefixIcon: Icon(Icons.badge_outlined),
|
||||||
|
),
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null || value.trim().isEmpty) {
|
||||||
|
return 'Escribe un alias';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
TextFormField(
|
||||||
|
controller: _streetController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Calle y número',
|
||||||
|
prefixIcon: Icon(Icons.home_outlined),
|
||||||
|
),
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null || value.trim().isEmpty) {
|
||||||
|
return 'Escribe la dirección';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
TextFormField(
|
||||||
|
controller: _coloniaController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Colonia',
|
||||||
|
prefixIcon: Icon(Icons.map_outlined),
|
||||||
|
),
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null || value.trim().isEmpty) {
|
||||||
|
return 'Escribe la colonia';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: ElevatedButton.icon(
|
||||||
|
onPressed: _saveAddress,
|
||||||
|
icon: const Icon(Icons.add_location_alt, color: Colors.white),
|
||||||
|
label: const Text('Guardar dirección'),
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: const Color(0xFF2E7D32),
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Text(
|
||||||
|
'Mis direcciones',
|
||||||
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
..._savedAddresses.map(
|
||||||
|
(address) => Card(
|
||||||
|
margin: const EdgeInsets.only(bottom: 12),
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
|
child: ListTile(
|
||||||
|
leading: const CircleAvatar(
|
||||||
|
backgroundColor: Color(0xFFE8F5E9),
|
||||||
|
child: Icon(Icons.route, color: Color(0xFF2E7D32)),
|
||||||
|
),
|
||||||
|
title: Text(address.alias, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||||
|
subtitle: Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 6),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(address.street),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(address.colonia),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 8,
|
||||||
|
children: [
|
||||||
|
_InfoChip(label: address.routeId, icon: Icons.local_shipping),
|
||||||
|
_InfoChip(label: address.schedule, icon: Icons.access_time),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
isThreeLine: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SavedAddress {
|
||||||
|
final String alias;
|
||||||
|
final String street;
|
||||||
|
final String colonia;
|
||||||
|
final String routeId;
|
||||||
|
final String schedule;
|
||||||
|
|
||||||
|
_SavedAddress({
|
||||||
|
required this.alias,
|
||||||
|
required this.street,
|
||||||
|
required this.colonia,
|
||||||
|
required this.routeId,
|
||||||
|
required this.schedule,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RouteInfo {
|
||||||
|
final String routeId;
|
||||||
|
final String schedule;
|
||||||
|
|
||||||
|
const _RouteInfo({required this.routeId, required this.schedule});
|
||||||
|
}
|
||||||
|
|
||||||
|
class _InfoChip extends StatelessWidget {
|
||||||
|
final String label;
|
||||||
|
final IconData icon;
|
||||||
|
|
||||||
|
const _InfoChip({required this.label, required this.icon});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xFFF1F8E9),
|
||||||
|
borderRadius: BorderRadius.circular(999),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(icon, size: 14, color: const Color(0xFF2E7D32)),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w600),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,533 +1,408 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
import '../../../../core/theme/app_theme.dart';
|
import '../../../../core/router/app_router.dart';
|
||||||
import '../bloc/auth_bloc.dart';
|
|
||||||
import '../bloc/auth_event.dart';
|
|
||||||
import '../bloc/auth_state.dart';
|
|
||||||
|
|
||||||
/// Pantalla principal post-login — MVP WasteNotify.
|
class HomeScreenPlaceholder extends StatefulWidget {
|
||||||
///
|
|
||||||
/// Cascarón de la pantalla de inicio. En fases futuras contendrá:
|
|
||||||
/// - ETA de llegada del camión (sin mapa, solo tiempo estimado)
|
|
||||||
/// - Notificaciones programadas
|
|
||||||
/// - Historial de recolecciones
|
|
||||||
/// - Panel de operador (si role == 'operator')
|
|
||||||
///
|
|
||||||
/// RESTRICCIÓN DE PRIVACIDAD: Esta pantalla NO mostrará mapas de rutas
|
|
||||||
/// ni la posición GPS del vehículo. Solo tiempo estimado de llegada.
|
|
||||||
class HomeScreenPlaceholder extends StatelessWidget {
|
|
||||||
const HomeScreenPlaceholder({super.key});
|
const HomeScreenPlaceholder({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
State<HomeScreenPlaceholder> createState() => _HomeScreenPlaceholderState();
|
||||||
return BlocBuilder<AuthBloc, AuthState>(
|
}
|
||||||
builder: (context, state) {
|
|
||||||
final user = state is AuthAuthenticated ? state.user : null;
|
|
||||||
final isOperator = user?.role == 'operator';
|
|
||||||
|
|
||||||
return Scaffold(
|
class _HomeScreenPlaceholderState extends State<HomeScreenPlaceholder> {
|
||||||
backgroundColor: AppTheme.warmWhite,
|
// 1. Catálogo de Colonias tipado fuertemente con tu nuevo modelo (Mapeo de tu JSON)
|
||||||
appBar: AppBar(
|
final List<ColoniaModel> _coloniasData = [
|
||||||
title: Row(
|
ColoniaModel(colonia: "Zona Centro", routeId: "RUTA-01", horarioEstimado: "Matutino (06:30 - 07:15)"),
|
||||||
children: [
|
ColoniaModel(colonia: "Las Arboledas", routeId: "RUTA-01", horarioEstimado: "Matutino (07:00 - 07:30)"),
|
||||||
const Icon(Icons.recycling_rounded,
|
ColoniaModel(colonia: "Trojes", routeId: "RUTA-13", horarioEstimado: "Matutino (06:40 - 07:10)"),
|
||||||
color: AppTheme.leafGreen, size: 22),
|
ColoniaModel(colonia: "San Juanico", routeId: "RUTA-03", horarioEstimado: "Matutino (06:45 - 07:15)"),
|
||||||
const SizedBox(width: 8),
|
ColoniaModel(colonia: "Los Olivos", routeId: "RUTA-04", horarioEstimado: "Matutino (07:00 - 07:40)"),
|
||||||
RichText(
|
ColoniaModel(colonia: "Rancho Seco", routeId: "RUTA-05", horarioEstimado: "Vespertino (14:15 - 15:00)"),
|
||||||
text: const TextSpan(
|
ColoniaModel(colonia: "Las Insurgentes", routeId: "RUTA-12", horarioEstimado: "Matutino (06:35 - 07:10)")
|
||||||
style: TextStyle(
|
];
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w700,
|
// 2. Diccionario de Telemetría Satelital de Celaya (Mapeo de tus imágenes)
|
||||||
color: AppTheme.charcoal,
|
final Map<String, Map<String, dynamic>> _routesTelemetry = {
|
||||||
),
|
"RUTA-01": {
|
||||||
children: [
|
"name": "Zona Centro - Las Arboledas",
|
||||||
TextSpan(text: 'Waste'),
|
"truckId": 101,
|
||||||
TextSpan(
|
"positions": [
|
||||||
text: 'Notify',
|
{"positionId": 1, "lat": 20.5111, "lng": -100.9037, "speed": 0, "desc": "Salida Relleno Sanitario", "mins": "45"},
|
||||||
style: TextStyle(color: AppTheme.leafGreen),
|
{"positionId": 2, "lat": 20.5185, "lng": -100.8450, "speed": 45, "desc": "En trayecto principal", "mins": "30"},
|
||||||
),
|
{"positionId": 3, "lat": 20.5215, "lng": -100.8142, "speed": 22, "desc": "Ingresando a zona Centro", "mins": "20"},
|
||||||
],
|
{"positionId": 4, "lat": 20.5212, "lng": -100.8175, "speed": 15, "desc": "Punto Previo Destino (<15 min)", "mins": "12"},
|
||||||
),
|
{"positionId": 5, "lat": 20.5210, "lng": -100.8210, "speed": 0, "desc": "Recolección Activa de Residuos", "mins": "5"},
|
||||||
),
|
{"positionId": 6, "lat": 20.5235, "lng": -100.8212, "speed": 18, "desc": "Avanzando sector Arboledas", "mins": "3"},
|
||||||
],
|
{"positionId": 7, "lat": 20.5260, "lng": -100.8215, "speed": 20, "desc": "Última parada del circuito", "mins": "1"},
|
||||||
),
|
{"positionId": 8, "lat": 20.5111, "lng": -100.9037, "speed": 40, "desc": "Retorno al Basurero Municipal", "mins": "0"}
|
||||||
actions: [
|
]
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.logout_rounded),
|
|
||||||
tooltip: 'Cerrar sesión',
|
|
||||||
onPressed: () {
|
|
||||||
context.read<AuthBloc>().add(const AuthLogoutRequested());
|
|
||||||
},
|
},
|
||||||
),
|
"RUTA-03": {
|
||||||
],
|
"name": "Sector Poniente - San Juanico",
|
||||||
),
|
"truckId": 103,
|
||||||
body: CustomScrollView(
|
"positions": [
|
||||||
slivers: [
|
{"positionId": 1, "lat": 20.5111, "lng": -100.9037, "speed": 0, "desc": "Salida Base de Monitoreo", "mins": "40"},
|
||||||
SliverPadding(
|
{"positionId": 2, "lat": 20.5250, "lng": -100.8510, "speed": 42, "desc": "Vía Rápida Poniente", "mins": "25"},
|
||||||
padding: const EdgeInsets.all(20),
|
{"positionId": 3, "lat": 20.5290, "lng": -100.8320, "speed": 20, "desc": "Eje Norponiente", "mins": "18"},
|
||||||
sliver: SliverList(
|
{"positionId": 4, "lat": 20.5315, "lng": -100.8355, "speed": 15, "desc": "Avenida San Juanico", "mins": "10"},
|
||||||
delegate: SliverChildListDelegate([
|
{"positionId": 5, "lat": 20.5340, "lng": -100.8390, "speed": 0, "desc": "Vaciado de Contenedores Urbano", "mins": "6"},
|
||||||
// --- Bienvenida ---
|
{"positionId": 8, "lat": 20.5111, "lng": -100.9037, "speed": 35, "desc": "Retorno General", "mins": "0"}
|
||||||
_WelcomeCard(user: user),
|
]
|
||||||
const SizedBox(height: 20),
|
},
|
||||||
|
"RUTA-04": {
|
||||||
|
"name": "Oriente - Los Olivos",
|
||||||
|
"truckId": 104,
|
||||||
|
"positions": [
|
||||||
|
{"positionId": 1, "lat": 20.5111, "lng": -100.9037, "speed": 0, "desc": "Encendido de Unidad", "mins": "50"},
|
||||||
|
{"positionId": 4, "lat": 20.5320, "lng": -100.7850, "speed": 12, "desc": "Proximidad Los Olivos", "mins": "14"},
|
||||||
|
{"positionId": 5, "lat": 20.5350, "lng": -100.7790, "speed": 0, "desc": "Recolección Casa por Casa", "mins": "8"},
|
||||||
|
{"positionId": 8, "lat": 20.5111, "lng": -100.9037, "speed": 48, "desc": "Retorno a Relleno Sanitario", "mins": "0"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// --- ETA Principal (cascarón) ---
|
int _activePositionIndex = 0;
|
||||||
const _EtaCard(),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
|
|
||||||
// --- Mensaje preventivo ---
|
// 📍 Historial tipado de forma segura con el modelo de notificaciones push
|
||||||
const _PreventiveMessageCard(),
|
final List<NotificationModel> _pushNotificationsLog = [];
|
||||||
const SizedBox(height: 20),
|
|
||||||
|
|
||||||
// --- Próximas funcionalidades ---
|
String _userColonia = "Zona Centro";
|
||||||
_UpcomingFeatures(isOperator: isOperator),
|
bool _isInitialized = false;
|
||||||
const SizedBox(height: 20),
|
|
||||||
|
|
||||||
// --- Info de sesión (debug MVP) ---
|
@override
|
||||||
if (user != null) _SessionDebugCard(user: user),
|
void initState() {
|
||||||
]),
|
super.initState();
|
||||||
),
|
_userColonia = "Zona Centro"; // Forzado de respaldo seguro
|
||||||
),
|
_isInitialized = true;
|
||||||
],
|
|
||||||
),
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
_triggerNotificationCheck();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
try {
|
||||||
|
final uri = GoRouterState.of(context).uri;
|
||||||
|
final String? coloniaParam = uri.queryParameters['colonia'];
|
||||||
|
|
||||||
|
if (coloniaParam != null &&
|
||||||
|
coloniaParam.isNotEmpty &&
|
||||||
|
_coloniasData.any((e) => e.colonia.toLowerCase() == coloniaParam.toLowerCase())) {
|
||||||
|
|
||||||
|
final elementoEncontrado = _coloniasData.firstWhere(
|
||||||
|
(e) => e.colonia.toLowerCase() == coloniaParam.toLowerCase()
|
||||||
);
|
);
|
||||||
},
|
setState(() {
|
||||||
|
_userColonia = elementoEncontrado.colonia;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Manejo silencioso de GoRouter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lógica interactiva que dispara las notificaciones basadas en tu modelo real
|
||||||
|
void _triggerNotificationCheck() {
|
||||||
|
final String currentRouteId = _getColoniaInfo().routeId;
|
||||||
|
if (!_routesTelemetry.containsKey(currentRouteId)) return;
|
||||||
|
|
||||||
|
final telemetry = _routesTelemetry[currentRouteId]!;
|
||||||
|
final currentPos = (telemetry["positions"] as List)[_activePositionIndex];
|
||||||
|
final int pId = currentPos["positionId"];
|
||||||
|
|
||||||
|
NotificationModel? newAlert;
|
||||||
|
|
||||||
|
if (pId == 2) {
|
||||||
|
newAlert = NotificationModel(
|
||||||
|
triggerEvent: "ROUTE_START",
|
||||||
|
condition: "Cuando positionId cambia de 1 a 2",
|
||||||
|
pushPayload: PushPayloadModel(
|
||||||
|
title: "¡Ruta Iniciada!",
|
||||||
|
body: "El camión recolector ha salido del Relleno Sanitario rumbo a tu sector. Asegúrate de tener listos tus residuos."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (pId == 4) {
|
||||||
|
newAlert = NotificationModel(
|
||||||
|
triggerEvent: "TRUCK_PROXIMITY",
|
||||||
|
condition: "Cuando positionId llega a 4 (punto previo al destino)",
|
||||||
|
pushPayload: PushPayloadModel(
|
||||||
|
title: "Camión Cercano",
|
||||||
|
body: "El camión está a menos de 15 minutos de tu domicilio. Es momento de sacar tus bolsas a la acera."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (pId == 8) {
|
||||||
|
newAlert = NotificationModel(
|
||||||
|
triggerEvent: "ROUTE_COMPLETED",
|
||||||
|
condition: "Cuando positionId llega a 8 (retorno al basurero)",
|
||||||
|
pushPayload: PushPayloadModel(
|
||||||
|
title: "Servicio Finalizado",
|
||||||
|
body: "El camión de tu sector ha concluido su jornada de recolección diaria."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newAlert != null) {
|
||||||
|
setState(() {
|
||||||
|
_pushNotificationsLog.insert(0, newAlert!);
|
||||||
|
});
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('🔔 Push: ${newAlert.pushPayload.title}'),
|
||||||
|
backgroundColor: pId == 4 ? Colors.amber.shade900 : (pId == 8 ? Colors.blue.shade700 : Colors.green.shade700),
|
||||||
|
duration: const Duration(seconds: 2),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
ColoniaModel _getColoniaInfo() {
|
||||||
// Sub-widgets de la pantalla home
|
return _coloniasData.firstWhere(
|
||||||
// ---------------------------------------------------------------------------
|
(element) => element.colonia == _userColonia,
|
||||||
|
orElse: () => _coloniasData.first,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
class _WelcomeCard extends StatelessWidget {
|
void _nextSimulationStep() {
|
||||||
final dynamic user;
|
final String currentRouteId = _getColoniaInfo().routeId;
|
||||||
|
if (!_routesTelemetry.containsKey(currentRouteId)) return;
|
||||||
|
|
||||||
const _WelcomeCard({required this.user});
|
final positionsList = _routesTelemetry[currentRouteId]!["positions"] as List;
|
||||||
|
if (_activePositionIndex < positionsList.length - 1) {
|
||||||
|
setState(() {
|
||||||
|
_activePositionIndex++;
|
||||||
|
});
|
||||||
|
_triggerNotificationCheck();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final roleLabel = user?.role == 'operator' ? 'Operador' : 'Ciudadano';
|
final coloniaInfo = _getColoniaInfo();
|
||||||
final identifier = user?.email ?? '';
|
final String routeId = coloniaInfo.routeId;
|
||||||
|
|
||||||
return Container(
|
final telemetry = _routesTelemetry[routeId]!;
|
||||||
padding: const EdgeInsets.all(20),
|
final currentPositionData = (telemetry["positions"] as List)[_activePositionIndex];
|
||||||
decoration: BoxDecoration(
|
|
||||||
gradient: const LinearGradient(
|
return Scaffold(
|
||||||
colors: [AppTheme.leafGreen, AppTheme.forestGreen],
|
backgroundColor: const Color(0xFFF5F5F5),
|
||||||
begin: Alignment.topLeft,
|
appBar: AppBar(
|
||||||
end: Alignment.bottomRight,
|
title: Row(
|
||||||
|
children: const [
|
||||||
|
Icon(Icons.recycling, color: Color(0xFF2E7D32)),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
Text('WasteNotify', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20, color: Colors.black)),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
borderRadius: BorderRadius.circular(16),
|
backgroundColor: Colors.white,
|
||||||
boxShadow: [
|
elevation: 0,
|
||||||
BoxShadow(
|
actions: [
|
||||||
color: AppTheme.leafGreen.withOpacity(0.3),
|
IconButton(
|
||||||
blurRadius: 16,
|
icon: const Icon(Icons.logout, color: Colors.black),
|
||||||
offset: const Offset(0, 6),
|
onPressed: () => context.go('/login'),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
bottomNavigationBar: NavigationBar(
|
||||||
|
selectedIndex: 0,
|
||||||
|
onDestinationSelected: (index) {
|
||||||
|
if (index == 1) {
|
||||||
|
context.go(AppRoutes.addresses);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
destinations: const [
|
||||||
|
NavigationDestination(
|
||||||
|
icon: Icon(Icons.home_outlined),
|
||||||
|
selectedIcon: Icon(Icons.home),
|
||||||
|
label: 'Inicio',
|
||||||
|
),
|
||||||
|
NavigationDestination(
|
||||||
|
icon: Icon(Icons.location_on_outlined),
|
||||||
|
selectedIcon: Icon(Icons.location_on),
|
||||||
|
label: 'Direcciones',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
// --- 1. TARJETA DE BIENVENIDA ---
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xFF1B5E20),
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
const CircleAvatar(
|
||||||
width: 52,
|
backgroundColor: Colors.white24,
|
||||||
height: 52,
|
radius: 24,
|
||||||
decoration: BoxDecoration(
|
child: Icon(Icons.person, color: Colors.white, size: 28),
|
||||||
color: Colors.white.withOpacity(0.2),
|
|
||||||
borderRadius: BorderRadius.circular(13),
|
|
||||||
),
|
|
||||||
child: const Icon(
|
|
||||||
Icons.person_rounded,
|
|
||||||
color: Colors.white,
|
|
||||||
size: 30,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
Expanded(
|
Column(
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
const Text('¡Bienvenido!', style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold)),
|
||||||
'¡Bienvenido!',
|
const SizedBox(height: 6),
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white70,
|
|
||||||
fontSize: 13,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
identifier,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 15,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
),
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Container(
|
Container(
|
||||||
padding:
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||||
const EdgeInsets.symmetric(horizontal: 10, vertical: 3),
|
decoration: BoxDecoration(color: Colors.white24, borderRadius: BorderRadius.circular(12)),
|
||||||
decoration: BoxDecoration(
|
child: const Text('Ciudadano', style: TextStyle(color: Colors.white, fontSize: 12)),
|
||||||
color: Colors.white.withOpacity(0.2),
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
),
|
),
|
||||||
child: Text(
|
],
|
||||||
roleLabel,
|
),
|
||||||
style: const TextStyle(
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// --- 2. RELOJ DE TIEMPO ESTIMADO INTERACTIVO ---
|
||||||
|
Card(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontSize: 11,
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||||
fontWeight: FontWeight.w600,
|
elevation: 1,
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _EtaCard extends StatelessWidget {
|
|
||||||
const _EtaCard();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Card(
|
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(20.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: const [
|
||||||
Container(
|
Icon(Icons.access_time, color: Color(0xFF2E7D32)),
|
||||||
padding: const EdgeInsets.all(8),
|
SizedBox(width: 10),
|
||||||
decoration: BoxDecoration(
|
Text('Tiempo estimado de llegada', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.black)),
|
||||||
color: AppTheme.lightMint,
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
),
|
|
||||||
child: const Icon(
|
|
||||||
Icons.schedule_rounded,
|
|
||||||
color: AppTheme.leafGreen,
|
|
||||||
size: 22,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
const Expanded(
|
|
||||||
child: Text(
|
|
||||||
'Tiempo estimado de llegada',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 15,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
color: AppTheme.charcoal,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 16),
|
||||||
Center(
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Container(
|
Container(
|
||||||
width: 110,
|
width: 110,
|
||||||
height: 110,
|
height: 110,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(shape: BoxShape.circle, border: Border.all(color: const Color(0xFFE0E0E0), width: 3)),
|
||||||
shape: BoxShape.circle,
|
child: Column(
|
||||||
border: Border.all(
|
|
||||||
color: AppTheme.lightMint,
|
|
||||||
width: 6,
|
|
||||||
),
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
child: const Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Text('${currentPositionData["mins"]}', style: const TextStyle(fontSize: 32, fontWeight: FontWeight.bold, color: Colors.black)),
|
||||||
Icons.hourglass_empty_rounded,
|
Text('— min', style: TextStyle(fontSize: 14, color: Colors.grey.shade600)),
|
||||||
color: AppTheme.midGray,
|
|
||||||
size: 28,
|
|
||||||
),
|
|
||||||
SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
'— min',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 22,
|
|
||||||
fontWeight: FontWeight.w800,
|
|
||||||
color: AppTheme.midGray,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 14),
|
|
||||||
Text(
|
|
||||||
'Notificaciones activas próximamente',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: AppTheme.midGray,
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 12, vertical: 5),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: AppTheme.lightMint,
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
),
|
|
||||||
child: const Text(
|
|
||||||
'Fase 2 — En desarrollo',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 11,
|
|
||||||
color: AppTheme.leafGreen,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _PreventiveMessageCard extends StatelessWidget {
|
|
||||||
const _PreventiveMessageCard();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: AppTheme.alertAmber.withOpacity(0.08),
|
|
||||||
borderRadius: BorderRadius.circular(14),
|
|
||||||
border: Border.all(
|
|
||||||
color: AppTheme.alertAmber.withOpacity(0.3),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.campaign_outlined,
|
|
||||||
color: AppTheme.alertAmber, size: 18),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
'Recuerda siempre',
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
fontSize: 13,
|
|
||||||
color: AppTheme.earthBrown,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
_ReminderItem(
|
|
||||||
'🚮',
|
|
||||||
'Saca la basura SOLO cuando recibas la alerta de "próxima llegada".',
|
|
||||||
),
|
|
||||||
_ReminderItem(
|
|
||||||
'🚫',
|
|
||||||
'Nunca persigas ni te acerques al camión. El sistema te avisará a tiempo.',
|
|
||||||
),
|
|
||||||
_ReminderItem(
|
|
||||||
'🌱',
|
|
||||||
'Separar tus residuos hace más eficiente la recolección. ¡Gracias!',
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ReminderItem extends StatelessWidget {
|
|
||||||
final String emoji;
|
|
||||||
final String text;
|
|
||||||
|
|
||||||
const _ReminderItem(this.emoji, this.text);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 6),
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(emoji, style: const TextStyle(fontSize: 14)),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
text,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 12.5,
|
|
||||||
color: AppTheme.earthBrown,
|
|
||||||
height: 1.4,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _UpcomingFeatures extends StatelessWidget {
|
|
||||||
final bool isOperator;
|
|
||||||
|
|
||||||
const _UpcomingFeatures({required this.isOperator});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final features = [
|
|
||||||
(Icons.notifications_active_outlined, 'Alertas push de recolección',
|
|
||||||
'Fase 2'),
|
|
||||||
(Icons.history_rounded, 'Historial de notificaciones', 'Fase 2'),
|
|
||||||
(Icons.settings_outlined, 'Configurar zona y horario', 'Fase 3'),
|
|
||||||
if (isOperator) ...[
|
|
||||||
(Icons.bar_chart_rounded, 'Panel de rutas completadas', 'Fase 3'),
|
|
||||||
(Icons.group_outlined, 'Gestión de sectores', 'Fase 4'),
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return Card(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const Text(
|
|
||||||
'Próximamente en WasteNotify',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
color: AppTheme.charcoal,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
...features.map((f) => _FeatureRow(
|
Text('Estado GPS: ${currentPositionData["desc"]}', textAlign: TextAlign.center, style: TextStyle(fontSize: 13, color: Colors.grey.shade600, fontStyle: FontStyle.italic)),
|
||||||
icon: f.$1,
|
|
||||||
label: f.$2,
|
|
||||||
phase: f.$3,
|
|
||||||
)),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// --- 3. BOTÓN DE SIMULACIÓN PARA EL MVP ---
|
||||||
|
ElevatedButton.icon(
|
||||||
|
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFF2E7D32), padding: const EdgeInsets.symmetric(vertical: 14), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14))),
|
||||||
|
onPressed: _activePositionIndex < (telemetry['positions'] as List).length - 1 ? _nextSimulationStep : null,
|
||||||
|
icon: const Icon(Icons.play_arrow, color: Colors.white),
|
||||||
|
label: const Text('Simular Avance del Camión (GPS)', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// --- 4. BANDEJA DE ALERTAS REALES RECIBIDAS (PARSED) ---
|
||||||
|
if (_pushNotificationsLog.isNotEmpty) ...[
|
||||||
|
const Text('🔔 Alertas Push en Vivo', style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold, color: Colors.black)),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
..._pushNotificationsLog.map((log) {
|
||||||
|
final bool isWarning = log.triggerEvent == 'TRUCK_PROXIMITY';
|
||||||
|
final bool isDone = log.triggerEvent == 'ROUTE_COMPLETED';
|
||||||
|
final Color cardColor = isWarning ? Colors.amber.shade900 : (isDone ? Colors.blue.shade700 : Colors.green.shade700);
|
||||||
|
return Card(
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
|
child: ListTile(
|
||||||
|
leading: CircleAvatar(backgroundColor: cardColor.withOpacity(0.12), child: Icon(isWarning ? Icons.notification_important : (isDone ? Icons.check_circle : Icons.local_shipping), color: cardColor)),
|
||||||
|
title: Text(log.pushPayload.title, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14)),
|
||||||
|
subtitle: Text(log.pushPayload.body, style: const TextStyle(fontSize: 12)),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}).toList(),
|
||||||
}
|
const SizedBox(height: 16),
|
||||||
|
],
|
||||||
|
|
||||||
class _FeatureRow extends StatelessWidget {
|
// --- 5. PANEL DE RECOMENDACIONES ---
|
||||||
final IconData icon;
|
|
||||||
final String label;
|
|
||||||
final String phase;
|
|
||||||
|
|
||||||
const _FeatureRow({
|
|
||||||
required this.icon,
|
|
||||||
required this.label,
|
|
||||||
required this.phase,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 10),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(icon, size: 18, color: AppTheme.mintGreen),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 13, color: AppTheme.charcoal),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Container(
|
Container(
|
||||||
padding:
|
padding: const EdgeInsets.all(16),
|
||||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
decoration: BoxDecoration(color: const Color(0xFFFFF3E0), borderRadius: BorderRadius.circular(16), border: Border.all(color: const Color(0xFFFFE0B2))),
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: AppTheme.lightGray,
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
phase,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 10,
|
|
||||||
color: AppTheme.midGray,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SessionDebugCard extends StatelessWidget {
|
|
||||||
final dynamic user;
|
|
||||||
|
|
||||||
const _SessionDebugCard({required this.user});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final token = user?.token ?? '';
|
|
||||||
final tokenPreview =
|
|
||||||
token.length > 40 ? '${token.substring(0, 40)}…' : token;
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.all(14),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFF3E5F5),
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
border: Border.all(color: const Color(0xFFCE93D8), width: 1),
|
|
||||||
),
|
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const Row(
|
Row(children: const [Icon(Icons.campaign, color: Colors.orange, size: 22), SizedBox(width: 8), Text('Recuerda siempre', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.brown, fontSize: 14))]),
|
||||||
children: [
|
const SizedBox(height: 12),
|
||||||
Icon(Icons.developer_mode_rounded,
|
_buildBulletRow(Icons.delete_outline, 'Saca la basura SOLO cuando recibas la alerta de "próxima llegada".'),
|
||||||
size: 14, color: Color(0xFF7B1FA2)),
|
const SizedBox(height: 8),
|
||||||
SizedBox(width: 6),
|
_buildBulletRow(Icons.block, 'Nunca persigas ni te acerques al camión. El sistema te avisará a tiempo.'),
|
||||||
Text(
|
const SizedBox(height: 8),
|
||||||
'Debug — Sesión JWT (solo MVP)',
|
_buildBulletRow(Icons.eco_outlined, 'Separar tus residuos hace más eficiente la recolección. ¡Gracias!'),
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 11,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
color: Color(0xFF7B1FA2),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 6),
|
|
||||||
Text(
|
|
||||||
'Token: $tokenPreview',
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 10.5,
|
|
||||||
fontFamily: 'monospace',
|
|
||||||
color: Color(0xFF4A148C),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'Role: ${user?.role} | Expira: ${user?.expiresAt?.toLocal().toString().substring(0, 16)}',
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 10.5,
|
|
||||||
fontFamily: 'monospace',
|
|
||||||
color: Color(0xFF4A148C),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
|
||||||
|
const SizedBox(height: 20),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildBulletRow(IconData icon, String text) {
|
||||||
|
return Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Icon(icon, size: 16, color: Colors.brown.shade700),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Expanded(child: Text(text, style: TextStyle(fontSize: 13, color: Colors.brown.shade900, height: 1.2))),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// 📍 MODELO 1: Catálogo de Colonias
|
||||||
|
// =========================================================================
|
||||||
|
class ColoniaModel {
|
||||||
|
String colonia;
|
||||||
|
String routeId;
|
||||||
|
String horarioEstimado;
|
||||||
|
|
||||||
|
ColoniaModel({required this.colonia, required this.routeId, required this.horarioEstimado});
|
||||||
|
|
||||||
|
factory ColoniaModel.fromJson(Map<String, dynamic> json) => ColoniaModel(colonia: json['colonia'], routeId: json['routeId'], horarioEstimado: json['horarioEstimado']);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {'colonia': colonia, 'routeId': routeId, 'horarioEstimado': horarioEstimado};
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// 📍 MODELO 2: Sistema de Notificaciones Alertas Push
|
||||||
|
// =========================================================================
|
||||||
|
class NotificationModel {
|
||||||
|
String triggerEvent;
|
||||||
|
String condition;
|
||||||
|
PushPayloadModel pushPayload;
|
||||||
|
|
||||||
|
NotificationModel({required this.triggerEvent, required this.condition, required this.pushPayload});
|
||||||
|
|
||||||
|
factory NotificationModel.fromJson(Map<String, dynamic> json) => NotificationModel(triggerEvent: json['triggerEvent'], condition: json['condition'], pushPayload: PushPayloadModel.fromJson(json['pushPayload']));
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {'triggerEvent': triggerEvent, 'condition': condition, 'pushPayload': pushPayload.toJson()};
|
||||||
|
}
|
||||||
|
|
||||||
|
class PushPayloadModel {
|
||||||
|
String title;
|
||||||
|
String body;
|
||||||
|
|
||||||
|
PushPayloadModel({required this.title, required this.body});
|
||||||
|
|
||||||
|
factory PushPayloadModel.fromJson(Map<String, dynamic> json) => PushPayloadModel(title: json['title'], body: json['body']);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {'title': title, 'body': body};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
|
import 'home_screen_placeholder.dart'; // 📍 Ajusta las carpetas '../' según la ubicación exacta en tu proyecto
|
||||||
|
import '../../../../core/network/mysql_service.dart'; // 📍 Ajusta las carpetas '../' según tu proyecto
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
import '../../../../core/router/app_router.dart';
|
||||||
|
|
||||||
import '../../../../core/theme/app_theme.dart';
|
import '../../../../core/theme/app_theme.dart';
|
||||||
import '../bloc/auth_bloc.dart';
|
import '../bloc/auth_bloc.dart';
|
||||||
import '../bloc/auth_event.dart';
|
|
||||||
import '../bloc/auth_state.dart';
|
import '../bloc/auth_state.dart';
|
||||||
import '../widgets/privacy_notice_card.dart';
|
import '../widgets/privacy_notice_card.dart';
|
||||||
|
|
||||||
@@ -14,12 +17,16 @@ class LoginScreen extends StatefulWidget {
|
|||||||
State<LoginScreen> createState() => _LoginScreenState();
|
State<LoginScreen> createState() => _LoginScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _LoginScreenState extends State<LoginScreen> with SingleTickerProviderStateMixin {
|
class _LoginScreenState extends State<LoginScreen>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
final _identifierController = TextEditingController();
|
final _identifierController =
|
||||||
final _passwordController = TextEditingController();
|
TextEditingController(); // Controlador para el correo
|
||||||
|
final _passwordController =
|
||||||
|
TextEditingController(); // Controlador para la contraseña
|
||||||
|
|
||||||
bool _obscurePassword = true;
|
bool _obscurePassword = true;
|
||||||
|
|
||||||
late final AnimationController _animController;
|
late final AnimationController _animController;
|
||||||
late final Animation<double> _fadeAnim;
|
late final Animation<double> _fadeAnim;
|
||||||
late final Animation<Offset> _slideAnim;
|
late final Animation<Offset> _slideAnim;
|
||||||
@@ -31,17 +38,10 @@ class _LoginScreenState extends State<LoginScreen> with SingleTickerProviderStat
|
|||||||
vsync: this,
|
vsync: this,
|
||||||
duration: const Duration(milliseconds: 700),
|
duration: const Duration(milliseconds: 700),
|
||||||
);
|
);
|
||||||
_fadeAnim = CurvedAnimation(
|
_fadeAnim = CurvedAnimation(parent: _animController, curve: Curves.easeOut);
|
||||||
parent: _animController,
|
_slideAnim = Tween<Offset>(begin: const Offset(0, 0.06), end: Offset.zero)
|
||||||
curve: Curves.easeOut,
|
.animate(CurvedAnimation(
|
||||||
);
|
parent: _animController, curve: Curves.easeOutCubic));
|
||||||
_slideAnim = Tween<Offset>(
|
|
||||||
begin: const Offset(0, 0.06),
|
|
||||||
end: Offset.zero,
|
|
||||||
).animate(CurvedAnimation(
|
|
||||||
parent: _animController,
|
|
||||||
curve: Curves.easeOutCubic,
|
|
||||||
));
|
|
||||||
_animController.forward();
|
_animController.forward();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,16 +53,75 @@ class _LoginScreenState extends State<LoginScreen> with SingleTickerProviderStat
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _submit(BuildContext context) {
|
// 📍 CONSULTA REAL SELECT A TU TABLA DE MYSQL
|
||||||
|
void _submit(BuildContext context) async {
|
||||||
if (_formKey.currentState?.validate() ?? false) {
|
if (_formKey.currentState?.validate() ?? false) {
|
||||||
context.read<AuthBloc>().add(
|
try {
|
||||||
AuthLoginRequested(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
identifier: _identifierController.text,
|
const SnackBar(
|
||||||
password: _passwordController.text,
|
content: Text('Validando credenciales en MySQL Celaya...')),
|
||||||
|
);
|
||||||
|
|
||||||
|
// 1. Obtener la conexión por el cable USB Mapped
|
||||||
|
// 1. Obtener la conexión
|
||||||
|
final conn = await MySqlService().getConnection();
|
||||||
|
|
||||||
|
// 2. Modificamos el SELECT para traer también la columna 'colonia'
|
||||||
|
final result = await conn.execute(
|
||||||
|
"SELECT email, contrasena_hash, rol, colonia FROM usuarios WHERE email = :email",
|
||||||
|
{
|
||||||
|
"email": _identifierController.text.trim(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
if (result.rows.isNotEmpty) {
|
||||||
|
final usuarioEncontrado = result.rows.first.assoc();
|
||||||
|
final contrasenaEnBd = usuarioEncontrado['contrasena_hash'];
|
||||||
|
final email = usuarioEncontrado['email'];
|
||||||
|
final rol = usuarioEncontrado['rol'];
|
||||||
|
final colonia = usuarioEncontrado[
|
||||||
|
'colonia']; // 📍 Extraemos la colonia real de la BD
|
||||||
|
|
||||||
|
if (contrasenaEnBd?.trim() == _passwordController.text.trim()) {
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("¡Bienvenido de nuevo, $email ($rol)!")),
|
||||||
|
);
|
||||||
|
|
||||||
|
// 📍 Enviamos la colonia real extraída de MySQL directamente a la URL del Home
|
||||||
|
context.go('/home?colonia=$colonia');
|
||||||
|
} else {
|
||||||
|
// Contraseña mal mapeada en la BD
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('Contraseña incorrecta para este usuario'),
|
||||||
|
backgroundColor: Colors.orange),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// El correo de plano no existe en MySQL Workbench
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('El correo electrónico no está registrado'),
|
||||||
|
backgroundColor: Colors.orange),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"Error al conectar con MySQL: $e"), // 📍 CORREGIDO: Sin contra-barra para que pinte el error real
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
duration: const Duration(seconds: 5),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -73,7 +132,8 @@ class _LoginScreenState extends State<LoginScreen> with SingleTickerProviderStat
|
|||||||
SnackBar(
|
SnackBar(
|
||||||
content: Row(
|
content: Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.error_outline, color: Colors.white, size: 18),
|
const Icon(Icons.error_outline,
|
||||||
|
color: Colors.white, size: 18),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
Expanded(child: Text(state.message)),
|
Expanded(child: Text(state.message)),
|
||||||
],
|
],
|
||||||
@@ -86,8 +146,6 @@ class _LoginScreenState extends State<LoginScreen> with SingleTickerProviderStat
|
|||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
backgroundColor: AppTheme.warmWhite,
|
backgroundColor: AppTheme.warmWhite,
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Form(
|
|
||||||
key: _formKey,
|
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
slivers: [
|
slivers: [
|
||||||
SliverFillRemaining(
|
SliverFillRemaining(
|
||||||
@@ -99,23 +157,61 @@ class _LoginScreenState extends State<LoginScreen> with SingleTickerProviderStat
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 28),
|
padding: const EdgeInsets.symmetric(horizontal: 28),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 48),
|
const SizedBox(height: 48),
|
||||||
_buildHeader(),
|
_buildHeader(),
|
||||||
|
const SizedBox(height: 32),
|
||||||
|
_buildForm(context),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
const PrivacyNoticeCard(),
|
||||||
|
const SizedBox(height: 32),
|
||||||
|
_buildDemoHint(),
|
||||||
|
const Spacer(),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Center(
|
||||||
|
child: Text(
|
||||||
'Sistema Municipal de Recolección Residencial\nCelaya, Guanajuato',
|
'Sistema Municipal de Recolección Residencial\nCelaya, Guanajuato',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 12, color: Colors.grey.shade600, height: 1.3),
|
fontSize: 12,
|
||||||
|
color: Colors.grey.shade600,
|
||||||
|
height: 1.3),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 32),
|
),
|
||||||
// Asegúrate de que este widget esté definido en tu proyecto o cámbialo por un placeholder
|
const SizedBox(height: 48),
|
||||||
// const ScheduleWarningBanner(),
|
],
|
||||||
const SizedBox(height: 32),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// --- CAMPO: EMAIL / IDENTIFICADOR ---
|
Widget _buildHeader() {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: const [
|
||||||
|
Text('Bienvenido a WasteNotify',
|
||||||
|
style: TextStyle(fontSize: 26, fontWeight: FontWeight.bold)),
|
||||||
|
SizedBox(height: 8),
|
||||||
|
Text('Inicia sesión para continuar',
|
||||||
|
style: TextStyle(fontSize: 14, color: Colors.grey)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildForm(BuildContext context) {
|
||||||
|
return Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _identifierController,
|
controller: _identifierController,
|
||||||
keyboardType: TextInputType.emailAddress,
|
keyboardType: TextInputType.emailAddress,
|
||||||
@@ -125,39 +221,40 @@ class _LoginScreenState extends State<LoginScreen> with SingleTickerProviderStat
|
|||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.all(Radius.circular(12))),
|
borderRadius: BorderRadius.all(Radius.circular(12))),
|
||||||
),
|
),
|
||||||
validator: (value) =>
|
validator: (value) => (value == null || value.trim().isEmpty)
|
||||||
(value == null || value.trim().isEmpty)
|
|
||||||
? 'Por favor, ingresa tus datos de acceso'
|
? 'Por favor, ingresa tus datos de acceso'
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
|
||||||
// --- CAMPO: CONTRASEÑA ---
|
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _passwordController,
|
controller: _passwordController,
|
||||||
obscureText: _obscurePassword,
|
obscureText: _obscurePassword,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'Contraseña de Acceso',
|
labelText: 'Contraseña de Acceso',
|
||||||
prefixIcon: const Icon(Icons.lock_outline_rounded),
|
prefixIcon: const Icon(Icons.lock_outline_rounded),
|
||||||
suffixIcon: IconButton(
|
|
||||||
icon: Icon(_obscurePassword ? Icons.visibility_off : Icons.visibility),
|
|
||||||
onPressed: () => setState(() => _obscurePassword = !_obscurePassword),
|
|
||||||
),
|
|
||||||
border: const OutlineInputBorder(
|
border: const OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.all(Radius.circular(12))),
|
borderRadius: BorderRadius.all(Radius.circular(12))),
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
_obscurePassword ? Icons.visibility : Icons.visibility_off),
|
||||||
|
onPressed: () =>
|
||||||
|
setState(() => _obscurePassword = !_obscurePassword),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
validator: (value) => (value == null || value.isEmpty)
|
validator: (value) => (value == null || value.isEmpty)
|
||||||
? 'Por favor, introduce tu contraseña'
|
? 'Por favor, introduce tu contraseña'
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
|
|
||||||
// --- CONTENEDOR REACTIVO DE BOTONES ---
|
|
||||||
BlocBuilder<AuthBloc, AuthState>(
|
BlocBuilder<AuthBloc, AuthState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final isLoading = state is AuthLoading;
|
final isLoading = state is AuthLoading;
|
||||||
|
|
||||||
return AnimatedContainer(
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
AnimatedContainer(
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 200),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
@@ -165,7 +262,8 @@ class _LoginScreenState extends State<LoginScreen> with SingleTickerProviderStat
|
|||||||
? []
|
? []
|
||||||
: [
|
: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: AppTheme.leafGreen.withOpacity(0.3),
|
color:
|
||||||
|
AppTheme.leafGreen.withValues(alpha: 0.3),
|
||||||
blurRadius: 16,
|
blurRadius: 16,
|
||||||
offset: const Offset(0, 6),
|
offset: const Offset(0, 6),
|
||||||
),
|
),
|
||||||
@@ -175,38 +273,45 @@ class _LoginScreenState extends State<LoginScreen> with SingleTickerProviderStat
|
|||||||
onPressed: isLoading ? null : () => _submit(context),
|
onPressed: isLoading ? null : () => _submit(context),
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: isLoading
|
backgroundColor: isLoading
|
||||||
? AppTheme.mintGreen.withOpacity(0.7)
|
? AppTheme.mintGreen.withValues(alpha: 0.7)
|
||||||
: AppTheme.leafGreen,
|
: AppTheme.leafGreen,
|
||||||
disabledBackgroundColor: AppTheme.mintGreen.withOpacity(0.6),
|
disabledBackgroundColor:
|
||||||
|
AppTheme.mintGreen.withValues(alpha: 0.6),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12)),
|
||||||
),
|
),
|
||||||
child: isLoading
|
child: isLoading
|
||||||
? const CircularProgressIndicator(color: Colors.white)
|
? const SizedBox(
|
||||||
: const Text('Iniciar Sesión', style: TextStyle(color: Colors.white)),
|
height: 20,
|
||||||
|
width: 20,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
color: Colors.white, strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: const Text('Iniciar Sesión',
|
||||||
|
style: TextStyle(color: Colors.white)),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
// 📍 BOTÓN DE REGISTRO CORREGIDO (child al final)
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => context.push(AppRoutes.register),
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
foregroundColor: AppTheme.leafGreen,
|
||||||
|
textStyle: const TextStyle(
|
||||||
|
fontSize: 14, fontWeight: FontWeight.w500),
|
||||||
|
),
|
||||||
|
child: const Text('¿No tienes cuenta? Regístrate aquí'),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
|
||||||
const PrivacyNoticeCard(),
|
|
||||||
const SizedBox(height: 32),
|
|
||||||
_buildDemoHint(),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
} // 📍 Cierre de la función _buildForm
|
||||||
|
|
||||||
// Métodos auxiliares creados como placeholders para evitar errores de compilación
|
// Placeholders para evitar errores si no están definidos
|
||||||
Widget _buildHeader() => const Center(child: Text("WasteNotify", style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)));
|
Widget _buildDemoHint() => const SizedBox.shrink();
|
||||||
Widget _buildDemoHint() => const Center(child: Text("Demo: ciudadano@ejemplo.com / password123", style: TextStyle(fontSize: 12)));
|
} // 📍 Cierre de la clase _LoginScreenState
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:math'; //
|
||||||
|
import '../../../../core/network/mysql_service.dart'; // 📍 Ajusta las carpetas '../' según tu proyecto
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:flutter_application_1/features/auth/data/models/mock_waste_data.dart';
|
import 'package:flutter_application_1/features/auth/data/models/mock_waste_data.dart';
|
||||||
@@ -11,11 +13,29 @@ class RegisterScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _RegisterScreenState extends State<RegisterScreen> {
|
class _RegisterScreenState extends State<RegisterScreen> {
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
String _selectedColonia = 'Centro';
|
late String _selectedColonia;
|
||||||
final _nameController = TextEditingController();
|
final _nameController = TextEditingController();
|
||||||
final _emailController = TextEditingController();
|
final _emailController = TextEditingController();
|
||||||
final _passwordController = TextEditingController();
|
final _passwordController = TextEditingController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
if (MockWasteData.schedules.isNotEmpty) {
|
||||||
|
_selectedColonia = MockWasteData.schedules.first.colonia;
|
||||||
|
} else {
|
||||||
|
_selectedColonia = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_nameController.dispose();
|
||||||
|
_emailController.dispose();
|
||||||
|
_passwordController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -27,7 +47,8 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.assignment_ind_outlined, size: 80, color: Colors.green),
|
const Icon(Icons.assignment_ind_outlined,
|
||||||
|
size: 80, color: Colors.green),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Text(
|
Text(
|
||||||
'Regístrate para recibir avisos de recolección en tu zona',
|
'Regístrate para recibir avisos de recolección en tu zona',
|
||||||
@@ -37,64 +58,133 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _nameController,
|
controller: _nameController,
|
||||||
decoration: const InputDecoration(labelText: 'Nombre Completo', border: OutlineInputBorder()),
|
decoration: const InputDecoration(
|
||||||
validator: (v) => v!.isEmpty ? 'Ingresa tu nombre' : null,
|
labelText: 'Nombre Completo',
|
||||||
|
border: OutlineInputBorder()),
|
||||||
|
validator: (v) =>
|
||||||
|
v == null || v.isEmpty ? 'Ingresa tu nombre' : null,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _emailController,
|
controller: _emailController,
|
||||||
decoration: const InputDecoration(labelText: 'Correo o Teléfono', border: OutlineInputBorder()),
|
decoration: const InputDecoration(
|
||||||
validator: (v) => v!.isEmpty ? 'Ingresa tus datos' : null,
|
labelText: 'Correo o Teléfono',
|
||||||
|
border: OutlineInputBorder()),
|
||||||
|
validator: (v) =>
|
||||||
|
v == null || v.isEmpty ? 'Ingresa tus datos' : null,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _passwordController,
|
controller: _passwordController,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
decoration: const InputDecoration(labelText: 'Contraseña', border: OutlineInputBorder()),
|
decoration: const InputDecoration(
|
||||||
validator: (v) => v!.length < 6 ? 'Mínimo 6 caracteres' : null,
|
labelText: 'Contraseña', border: OutlineInputBorder()),
|
||||||
|
validator: (v) =>
|
||||||
|
v == null || v.length < 6 ? 'Mínimo 6 caracteres' : null,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
// Dropdown para seleccionar la Colonia (Requisito MVP)
|
|
||||||
DropdownButtonFormField<String>(
|
DropdownButtonFormField<String>(
|
||||||
value: _selectedColonia,
|
value: _selectedColonia,
|
||||||
decoration: const InputDecoration(labelText: 'Selecciona tu Colonia / Domicilio', border: OutlineInputBorder()),
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Selecciona tu Colonia / Domicilio',
|
||||||
|
border: OutlineInputBorder()),
|
||||||
items: MockWasteData.schedules.map((zone) {
|
items: MockWasteData.schedules.map((zone) {
|
||||||
return DropdownMenuItem(value: zone.colonia, child: Text(zone.colonia));
|
return DropdownMenuItem(
|
||||||
|
value: zone.colonia, child: Text(zone.colonia));
|
||||||
}).toList(),
|
}).toList(),
|
||||||
onChanged: (val) => setState(() => _selectedColonia = val!),
|
onChanged: (val) => setState(() => _selectedColonia = val!),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
|
|
||||||
// Mensajería Preventiva Legal
|
|
||||||
Card(
|
Card(
|
||||||
color: Colors.amber.shade50,
|
color: Colors.amber.shade50,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(12.0),
|
padding: const EdgeInsets.all(12.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
'🔒 Privacidad Garantizada:\nAl registrar tu domicilio, tu cuenta operará bajo el principio de "Visión de Túnel". Solo verás alertas de tu sector. Está prohibido el rastreo de flotillas.',
|
'🔒 Privacidad Garantizada:\nAl registrar tu domicilio, tu cuenta operará bajo el principio de "Visión de Túnel". Solo verás alertas de tu sector. Está prohibido el rastreo de flotillas.',
|
||||||
style: TextStyle(color: Colors.amber.shade900, fontSize: 13, fontWeight: FontWeight.bold),
|
style: TextStyle(
|
||||||
|
color: Colors.amber.shade900,
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
style: ElevatedButton.styleFrom(padding: const EdgeInsets.symmetric(vertical: 16), backgroundColor: Colors.green),
|
style: ElevatedButton.styleFrom(
|
||||||
onPressed: () {
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
|
backgroundColor: Colors.green),
|
||||||
|
onPressed: () async {
|
||||||
if (_formKey.currentState!.validate()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
// Simulación de Registro Exitoso: Navega al Home enviando la colonia elegida
|
try {
|
||||||
|
print(
|
||||||
|
'=== DEPURACIÓN: Iniciando proceso de registro ===');
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(content: Text('Cuenta creada con éxito (Modo Simulación)')),
|
const SnackBar(
|
||||||
|
content: Text(
|
||||||
|
'Conectando con la base de datos local...')),
|
||||||
|
);
|
||||||
|
|
||||||
|
final conn = await MySqlService().getConnection();
|
||||||
|
print(
|
||||||
|
'=== DEPURACIÓN: ¡Conexión obtenida! Estado connected: ${conn.connected}');
|
||||||
|
|
||||||
|
print('=== DEPURACIÓN: Intentando ejecutar INSERT ===');
|
||||||
|
final randomPhone =
|
||||||
|
'461${1000000 + Random().nextInt(9000000)}'; // 📍 ENVIANDO LA COLONIA REAL A TU NUEVA COLUMNA DE MYSQL
|
||||||
|
final result = await conn.execute(
|
||||||
|
"INSERT INTO usuarios (email, telefono, contrasena_hash, rol, is_verified, colonia) VALUES (:email, :telefono, :contrasena_hash, :rol, :is_verified, :colonia)",
|
||||||
|
{
|
||||||
|
"email": _emailController.text.trim(),
|
||||||
|
"telefono": randomPhone, // 📍 Genera un teléfono simulado para cumplir con el esquema de tu tabla
|
||||||
|
"contrasena_hash": _passwordController.text,
|
||||||
|
"rol": "Ciudadano",
|
||||||
|
"is_verified": 1,
|
||||||
|
"colonia":
|
||||||
|
_selectedColonia, // 📍 Envía la colonia seleccionada en el Dropdown
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
print(
|
||||||
|
'=== DEPURACIÓN: INSERT completado. Filas afectadas: ${result.affectedRows}');
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
if (result.affectedRows > BigInt.zero) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text(
|
||||||
|
'¡Usuario guardado con éxito en MySQL Celaya!')),
|
||||||
);
|
);
|
||||||
context.go('/home?colonia=$_selectedColonia');
|
context.go('/home?colonia=$_selectedColonia');
|
||||||
|
} else {
|
||||||
|
print(
|
||||||
|
'=== DEPURACIÓN: El query se ejecutó pero devolvió 0 filas afectadas ===');
|
||||||
|
}
|
||||||
|
} catch (e, stacktrace) {
|
||||||
|
print(
|
||||||
|
'=== DEPURACIÓN: ¡CAPTURADO UN ERROR EN EL CATCH! ===');
|
||||||
|
print('Detalle del error: $e');
|
||||||
|
print(
|
||||||
|
'Ubicación del fallo (Stacktrace): \n$stacktrace');
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Error de conexión a MySQL: $e'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
duration: const Duration(seconds: 5),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: const Text('Registrarse', style: TextStyle(color: Colors.white, fontSize: 16)),
|
child: const Text('Registrarse',
|
||||||
|
style: TextStyle(color: Colors.white, fontSize: 16)),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class PrivacyNoticeCard extends StatelessWidget {
|
|||||||
color: AppTheme.lightMint,
|
color: AppTheme.lightMint,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: AppTheme.mintGreen.withOpacity(0.3),
|
color: AppTheme.mintGreen.withValues(alpha: 0.3),
|
||||||
width: 1,
|
width: 1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -85,7 +85,7 @@ class _PrivacyPoint extends StatelessWidget {
|
|||||||
text,
|
text,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
color: AppTheme.forestGreen.withOpacity(0.85),
|
color: AppTheme.forestGreen.withValues(alpha: 0.85),
|
||||||
height: 1.4,
|
height: 1.4,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -105,10 +105,10 @@ class ScheduleWarningBanner extends StatelessWidget {
|
|||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: AppTheme.alertAmber.withOpacity(0.10),
|
color: AppTheme.alertAmber.withValues(alpha: 0.10),
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: AppTheme.alertAmber.withOpacity(0.35),
|
color: AppTheme.alertAmber.withValues(alpha: 0.35),
|
||||||
width: 1,
|
width: 1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
32
pubspec.lock
32
pubspec.lock
@@ -33,6 +33,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.1"
|
version: "2.1.1"
|
||||||
|
buffer:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: buffer
|
||||||
|
sha256: "389da2ec2c16283c8787e0adaede82b1842102f8c8aae2f49003a766c5c6b3d1"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.2.3"
|
||||||
characters:
|
characters:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -57,6 +65,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.19.0"
|
version: "1.19.0"
|
||||||
|
crypto:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: crypto
|
||||||
|
sha256: c8ea0233063ba03258fbcf2ca4d6dadfefe14f02fab57702265467a19f27fadf
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "3.0.7"
|
||||||
cupertino_icons:
|
cupertino_icons:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -304,6 +320,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.0"
|
version: "2.0.0"
|
||||||
|
mysql_client:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: mysql_client
|
||||||
|
sha256: "6a0fdcbe3e0721c637f97ad24649be2f70dbce2b21ede8f962910e640f753fc2"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.0.27"
|
||||||
nested:
|
nested:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -509,6 +533,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.10.1"
|
version: "0.10.1"
|
||||||
|
tuple:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: tuple
|
||||||
|
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.2"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ dependencies:
|
|||||||
flutter_map: ^6.2.1
|
flutter_map: ^6.2.1
|
||||||
latlong2: ^0.9.1
|
latlong2: ^0.9.1
|
||||||
flutter_local_notifications: ^19.5.0
|
flutter_local_notifications: ^19.5.0
|
||||||
|
mysql_client: ^0.0.27
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
// Use a local test app to avoid depending on external package imports
|
// Use a local test app to avoid depending on external package imports
|
||||||
// which may not exist in the test environment.
|
// which may not exist in the test environment.
|
||||||
class MyApp extends StatefulWidget {
|
class MyApp extends StatefulWidget {
|
||||||
const MyApp({Key? key}) : super(key: key);
|
const MyApp({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MyApp> createState() => _MyAppState();
|
State<MyApp> createState() => _MyAppState();
|
||||||
|
|||||||
Reference in New Issue
Block a user