Co-authored-by: MENDOZA BALLARDO GAEL RICARDO <gael-meb123@users.noreply.github.com>
Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.github.com>

modificacion de vistas panel admin, login, animaciones y implementacion de mascota
This commit is contained in:
shinra32
2026-05-23 03:58:03 -06:00
parent 45ffba69b2
commit 68d04f3917
33 changed files with 5188 additions and 643 deletions

View File

@@ -40,6 +40,7 @@ class _RegisterPageState extends ConsumerState<RegisterPage> {
final _step1FormKey = GlobalKey<FormState>();
// Paso 1
final _nameCtrl = TextEditingController();
final _emailCtrl = TextEditingController();
final _telefonoCtrl = TextEditingController();
final _passCtrl = TextEditingController();
@@ -91,6 +92,7 @@ class _RegisterPageState extends ConsumerState<RegisterPage> {
@override
void dispose() {
_pageController.dispose();
_nameCtrl.dispose();
_emailCtrl.dispose();
_telefonoCtrl.dispose();
_passCtrl.dispose();
@@ -201,77 +203,19 @@ class _RegisterPageState extends ConsumerState<RegisterPage> {
FocusScope.of(context).unfocus(); // Cierra el teclado
}
Future<void> _register() async {
if (_calleCtrl.text.trim().isEmpty || _selectedColonia == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ingresa tu calle y selecciona una colonia'),
behavior: SnackBarBehavior.floating,
),
);
return;
}
final phoneDigits = _telefonoCtrl.text.replaceAll(RegExp(r'\D'), '');
final phone = phoneDigits.isNotEmpty ? '+52$phoneDigits' : '';
final calle = _calleCtrl.text.trim();
final colonia = _selectedColonia!.nombre;
final lat = _selectedLocation?.latitude;
final lng = _selectedLocation?.longitude;
try {
await ref
.read(authControllerProvider.notifier)
.register(
email: _emailCtrl.text.trim(),
phone: phone,
password: _passCtrl.text,
addressCalle: calle,
addressColonia: colonia,
addressLabel: 'Mi Casa',
addressLat: lat,
addressLng: lng,
);
// Guardado silencioso de la dirección tras un registro exitoso
_postAddressInBackground(calle, colonia, lat, lng);
} catch (_) {
// El error ya es manejado por el listener y muestra el SnackBar
}
}
Future<void> _postAddressInBackground(
String calle,
String colonia,
double? lat,
double? lng,
) async {
try {
const storage = FlutterSecureStorage();
await Future.delayed(
const Duration(milliseconds: 800),
); // Esperar a que se guarde el JWT
final token = await storage.read(key: authTokenStorageKey) ?? '';
if (token.isNotEmpty) {
final dio = Dio(
BaseOptions(
baseUrl: const String.fromEnvironment(
'API_BASE_URL',
defaultValue: 'http://localhost:8000',
),
headers: {'Authorization': 'Bearer $token'},
),
);
await dio.post(
'/addresses',
data: {'label': 'Mi Casa', 'calle': calle, 'colonia': colonia},
);
}
} catch (e) {
debugPrint('Aviso: No se pudo crear la dirección: $e');
}
void _onRegister() {
final auth = ref.read(authControllerProvider.notifier);
auth.register(
name: _nameCtrl.text,
email: _emailCtrl.text,
phone: _telefonoCtrl.text,
password: _passCtrl.text,
addressCalle: _calleCtrl.text,
addressColonia: _selectedColonia?.nombre,
addressLabel: _tipoInmueble,
addressLat: _selectedLocation?.latitude,
addressLng: _selectedLocation?.longitude,
);
}
@override
@@ -299,35 +243,431 @@ class _RegisterPageState extends ConsumerState<RegisterPage> {
controller: _pageController,
physics: const NeverScrollableScrollPhysics(),
children: [
_Step1(
formKey: _step1FormKey,
emailCtrl: _emailCtrl,
telefonoCtrl: _telefonoCtrl,
passCtrl: _passCtrl,
obscurePass: _obscurePass,
onTogglePass: () => setState(() => _obscurePass = !_obscurePass),
onNext: _nextPage,
_buildStep1(context),
_buildStep2(context, loading, coloniasList),
],
),
bottomNavigationBar: _buildBottomControls(context, loading),
);
}
Widget _buildStep1(BuildContext context) {
return Form(
key: _step1FormKey,
child: ListView(
padding: const EdgeInsets.fromLTRB(20, 24, 20, 40),
children: [
const Text(
'Crea tu cuenta',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w700,
color: AppTheme.textPrimary,
),
),
_Step2(
mapController: _mapController,
cpCtrl: _cpCtrl,
calleCtrl: _calleCtrl,
selectedColonia: _selectedColonia,
selectedLocation: _selectedLocation,
tipoInmueble: _tipoInmueble,
whatsappNotif: _whatsappNotif,
loading: loading,
onTipoChanged: (v) => setState(() => _tipoInmueble = v),
onCPChanged: (v) => _validarCP(v, coloniasList),
onLocationChanged: _fetchStreetName,
onWhatsappChanged: (v) =>
setState(() => _whatsappNotif = v ?? false),
onRegister: _register,
const SizedBox(height: 8),
const Text(
'Ingresa tus datos para registrarte.',
style: TextStyle(fontSize: 15, color: AppTheme.textSecondary),
),
const SizedBox(height: 28),
AppFormField(
controller: _nameCtrl,
label: 'Nombre completo',
validator: (val) =>
val!.isEmpty ? 'Ingresa tu nombre completo' : null,
),
const SizedBox(height: 16),
AppFormField(
controller: _emailCtrl,
label: 'Correo electrónico',
hint: 'tu@correo.com',
keyboardType: TextInputType.emailAddress,
validator: (v) {
if (v == null || v.trim().isEmpty) return 'Ingresa tu correo';
final emailRegex = RegExp(r'^[^@]+@[^@]+\.[^@]+');
if (!emailRegex.hasMatch(v.trim()))
return 'Ingresa un correo válido';
return null;
},
),
const SizedBox(height: 14),
_PhoneField(controller: _telefonoCtrl),
const SizedBox(height: 14),
AppFormField(
label: 'Contraseña',
hint: '••••••••',
controller: _passCtrl,
obscureText: _obscurePass,
validator: (v) {
if (v == null || v.isEmpty) return 'Ingresa una contraseña';
if (v.length < 6) return 'Mínimo 6 caracteres';
return null;
},
suffix: IconButton(
icon: Icon(
_obscurePass
? Icons.visibility_outlined
: Icons.visibility_off_outlined,
size: 18,
color: AppTheme.textSecondary,
),
onPressed: () => setState(() => _obscurePass = !_obscurePass),
),
),
],
),
);
}
Widget _buildStep2(
BuildContext context,
bool loading,
List<Colonia> coloniasList,
) {
return SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
AppFormCard(
icon: Icons.home_outlined,
title: 'Dirección de tu casa',
child: Column(
children: [
const Text(
'Tipo de inmueble',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: AppTheme.textSecondary,
),
),
Row(
children: [
Expanded(
child: Material(
color: Colors.transparent,
child: RadioListTile<String>(
title: const Text(
'Casa',
style: TextStyle(fontSize: 14),
),
value: 'Casa',
groupValue: _tipoInmueble,
onChanged: (v) => setState(() => _tipoInmueble = v!),
),
),
),
Expanded(
child: Material(
color: Colors.transparent,
child: RadioListTile<String>(
title: const Text(
'Negocio',
style: TextStyle(fontSize: 14),
),
value: 'Negocio',
groupValue: _tipoInmueble,
onChanged: (v) => setState(() => _tipoInmueble = v!),
),
),
),
],
),
const SizedBox(height: 8),
AppFormField(
label: 'Código Postal',
hint: 'Ej. 38000',
controller: _cpCtrl,
keyboardType: TextInputType.number,
onChanged: (v) => _validarCP(v, coloniasList),
),
if (_selectedColonia != null) ...[
const SizedBox(height: 14),
Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: AppTheme.primaryLight.withValues(alpha: 0.5),
borderRadius: BorderRadius.circular(AppTheme.radiusSm),
border: Border.all(color: AppTheme.primaryMid),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(
Icons.check_circle_outline,
color: AppTheme.primary,
size: 18,
),
const SizedBox(width: 8),
Expanded(
child: Text(
'Colonia: ${_selectedColonia!.nombre}',
style: const TextStyle(
fontWeight: FontWeight.w600,
color: AppTheme.primaryDark,
),
),
),
],
),
const SizedBox(height: 8),
Text(
'Horario ${_selectedColonia!.turno?.toLowerCase() ?? 'asignado'}',
style: const TextStyle(
fontSize: 13,
color: AppTheme.textPrimary,
),
),
Text(
_selectedColonia!.horarioEstimado ??
'Sin horario especificado',
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: AppTheme.textPrimary,
),
),
],
),
),
const SizedBox(height: 14),
AppFormField(
label: 'Calle y número',
hint: 'Av. Insurgentes 245',
controller: _calleCtrl,
),
const SizedBox(height: 16),
const Text(
'Toca el mapa para ubicar tu casa exacta:',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: AppTheme.textSecondary,
),
),
const SizedBox(height: 8),
Container(
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(AppTheme.radiusSm),
border: Border.all(color: AppTheme.border),
),
clipBehavior: Clip.hardEdge,
child: FlutterMap(
mapController: _mapController,
options: MapOptions(
initialCenter:
_selectedLocation ??
const LatLng(20.5222, -100.8123),
initialZoom: 15.0,
onTap: (_, latlng) => _fetchStreetName(latlng),
),
children: [
TileLayer(
urlTemplate:
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.onlineshack.recolecta',
),
if (_selectedLocation != null)
MarkerLayer(
markers: [
Marker(
point: _selectedLocation!,
width: 40,
height: 40,
child: const Icon(
Icons.location_on,
color: AppTheme.danger,
size: 40,
),
),
],
),
],
),
),
] else ...[
const SizedBox(height: 24),
const Center(
child: Text(
'Ingresa un código postal con servicio\npara asignar tu colonia.',
textAlign: TextAlign.center,
style: TextStyle(
color: AppTheme.textSecondary,
fontSize: 13,
),
),
),
],
],
),
),
const SizedBox(height: 16),
// ── Sección OCR (Privacidad por diseño) ──
AppFormCard(
icon: Icons.document_scanner_outlined,
title: 'Verificación de Domicilio',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Para prevenir abusos, requerimos validar tu dirección con un recibo (luz o agua). '
'Por privacidad, la imagen será borrada inmediatamente después de la lectura.',
style: TextStyle(
fontSize: 13,
color: AppTheme.textSecondary,
height: 1.4,
),
),
const SizedBox(height: 14),
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
icon: const Icon(
Icons.upload_file,
color: AppTheme.primary,
),
label: const Text(
'Escanear recibo (OCR)',
style: TextStyle(color: AppTheme.primary),
),
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Abriendo cámara... (Próximamente)'),
),
);
},
),
),
],
),
),
const SizedBox(height: 16),
// ── Sección WhatsApp ──
AppFormCard(
icon: Icons.chat_outlined,
title: 'Notificaciones Externas',
child: Column(
children: [
Material(
color: Colors.transparent,
child: CheckboxListTile(
contentPadding: EdgeInsets.zero,
controlAffinity: ListTileControlAffinity.leading,
activeColor: AppTheme.primary,
value: _whatsappNotif,
onChanged: (v) =>
setState(() => _whatsappNotif = v ?? false),
title: const Text(
'Recibir alertas del camión vía WhatsApp (Próximamente)',
style: TextStyle(
fontSize: 14,
color: AppTheme.textPrimary,
),
),
),
),
],
),
),
const SizedBox(height: 28),
SizedBox(
width: double.infinity,
height: 52,
child: ElevatedButton(
onPressed: loading ? null : _onRegister,
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 200),
child: loading
? const SizedBox(
key: ValueKey('loading'),
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.white,
),
)
: const Row(
key: ValueKey('text'),
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.check, size: 18),
SizedBox(width: 8),
Flexible(
child: Text(
'Registrarme',
overflow: TextOverflow.ellipsis,
),
),
],
),
),
),
),
const SizedBox(height: 16),
const Center(
child: Text(
'Al registrarte aceptas los Términos de Servicio\ny la Política de Privacidad.',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 11,
color: AppTheme.textSecondary,
height: 1.5,
),
),
),
],
),
);
}
Widget _buildBottomControls(BuildContext context, bool isLoading) {
return Container(
padding: const EdgeInsets.all(
20,
).copyWith(bottom: MediaQuery.of(context).padding.bottom + 20),
decoration: const BoxDecoration(
color: AppTheme.background,
border: Border(top: BorderSide(color: AppTheme.border, width: 0.5)),
),
child: _currentPage == 0
? SizedBox(
width: double.infinity,
height: 52,
child: ElevatedButton(
onPressed: _nextPage,
child: const Text('Continuar'),
),
)
: SizedBox(
width: double.infinity,
height: 52,
child: ElevatedButton(
onPressed: isLoading ? null : _onRegister,
child: isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.white,
),
)
: const Text('Crear mi cuenta'),
),
),
);
}
}
// ── Indicador de pasos ────────────────────────────────────────────────────────
@@ -794,17 +1134,17 @@ class _Step2 extends StatelessWidget {
color: Colors.white,
),
)
: const Row(
: const FittedBox(
key: ValueKey('text'),
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.check, size: 18),
SizedBox(width: 8),
Flexible(
child: Text('Registrarme',
overflow: TextOverflow.ellipsis),
),
],
fit: BoxFit.scaleDown,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.check, size: 18),
SizedBox(width: 8),
Text('Registrarme'),
],
),
),
),
),