hotfix: navbar fixed
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
// main.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'src/views/domicilios.dart';
|
||||
import 'src/views/rutas.dart';
|
||||
import 'src/views/main_screen.dart';
|
||||
import 'src/views/login.dart'; // Importar LoginView
|
||||
import 'src/views/login.dart';
|
||||
import 'src/views/home_screen.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
@@ -61,10 +59,10 @@ class RegistroView extends StatelessWidget {
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15))
|
||||
),
|
||||
onPressed: () {
|
||||
// Navegar a MainScreen (app principal)
|
||||
// ✅ Navegar a HomeScreen (única barra de navegación)
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const DomiciliosView()),
|
||||
MaterialPageRoute(builder: (context) => const HomeScreen()),
|
||||
);
|
||||
},
|
||||
child: const Text('Registrar', style: TextStyle(color: Colors.white, fontSize: 18)),
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
// domicilios.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'rutas.dart';
|
||||
import '../models/domicilio_model.dart';
|
||||
import '../services/geolocation_service.dart';
|
||||
import 'nav_bar.dart';
|
||||
import 'main_screen.dart';
|
||||
|
||||
class DomiciliosView extends StatefulWidget {
|
||||
const DomiciliosView({super.key});
|
||||
@@ -102,17 +99,12 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ⬇️⬇️⬇️ ESTE ES EL MÉTODO QUE DEBES TENER ⬇️⬇️⬇️
|
||||
Future<void> _obtenerUbicacionYAgregar() async {
|
||||
print('🔵 Iniciando obtención de ubicación');
|
||||
setState(() {
|
||||
_isLoadingLocation = true;
|
||||
});
|
||||
|
||||
// Verificar GPS
|
||||
final serviceEnabled = await GeolocationService.isLocationServiceEnabled();
|
||||
print('📡 GPS activado: $serviceEnabled');
|
||||
|
||||
if (!serviceEnabled) {
|
||||
setState(() {
|
||||
_isLoadingLocation = false;
|
||||
@@ -121,69 +113,41 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
||||
const SnackBar(
|
||||
content: Text('Activa el GPS para agregar un domicilio'),
|
||||
backgroundColor: Colors.orange,
|
||||
duration: Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Verificar permisos
|
||||
final hasPermission = await _showLocationPermissionDialog();
|
||||
print('🔐 Permiso concedido: $hasPermission');
|
||||
|
||||
if (!hasPermission) {
|
||||
setState(() {
|
||||
_isLoadingLocation = false;
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Necesitamos tu ubicación para continuar'),
|
||||
content: Text('Necesitamos tu ubicación'),
|
||||
backgroundColor: Colors.orange,
|
||||
duration: Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Mostrar mensaje de "obteniendo ubicación"
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
Text('Obteniendo tu ubicación...'),
|
||||
],
|
||||
),
|
||||
backgroundColor: colorAzul,
|
||||
duration: Duration(seconds: 5),
|
||||
),
|
||||
);
|
||||
|
||||
// Obtener ubicación con reintentos
|
||||
final position = await GeolocationService.getCurrentLocationWithRetry(maxRetries: 3);
|
||||
final position = await GeolocationService.getCurrentLocation();
|
||||
|
||||
setState(() {
|
||||
_isLoadingLocation = false;
|
||||
});
|
||||
|
||||
if (position == null) {
|
||||
print('❌ No se pudo obtener ubicación después de reintentos');
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('No se pudo obtener tu ubicación. Revisa tu GPS.'),
|
||||
content: Text('No se pudo obtener tu ubicación.'),
|
||||
backgroundColor: Colors.red,
|
||||
duration: Duration(seconds: 4),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
print('✅ Ubicación obtenida exitosamente: ${position.latitude}, ${position.longitude}');
|
||||
_mostrarDialogoAgregarConUbicacion(position);
|
||||
}
|
||||
|
||||
@@ -204,17 +168,11 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'Añadir domicilio',
|
||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold, color: colorAzul),
|
||||
),
|
||||
const Text('Añadir domicilio', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold, color: colorAzul)),
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.green.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
decoration: BoxDecoration(color: Colors.green.withOpacity(0.1), borderRadius: BorderRadius.circular(12)),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.location_on, color: Colors.green[700], size: 24),
|
||||
@@ -223,8 +181,7 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('📍 Ubicación obtenida',
|
||||
style: TextStyle(fontSize: 12, color: Colors.green[700])),
|
||||
Text('📍 Ubicación obtenida', style: TextStyle(fontSize: 12, color: Colors.green[700])),
|
||||
Text('Lat: ${position.latitude.toStringAsFixed(6)}'),
|
||||
Text('Lng: ${position.longitude.toStringAsFixed(6)}'),
|
||||
],
|
||||
@@ -247,10 +204,7 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
style: OutlinedButton.styleFrom(
|
||||
side: BorderSide(color: colorAzul, width: 2),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
||||
),
|
||||
style: OutlinedButton.styleFrom(side: BorderSide(color: colorAzul, width: 2), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15))),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancelar', style: TextStyle(color: colorAzul)),
|
||||
),
|
||||
@@ -258,10 +212,7 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
||||
const SizedBox(width: 15),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: colorAzul,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
||||
),
|
||||
style: ElevatedButton.styleFrom(backgroundColor: colorAzul, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15))),
|
||||
onPressed: () => _agregarDomicilio(latitud: position.latitude, longitud: position.longitude),
|
||||
child: const Text('Agregar', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
@@ -289,14 +240,8 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
||||
hintText: hint,
|
||||
prefixIcon: Icon(icon, color: colorAzul),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(15)),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
borderSide: BorderSide(color: colorAzul.withOpacity(0.5)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
borderSide: const BorderSide(color: colorAzul, width: 2),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(15), borderSide: BorderSide(color: colorAzul.withOpacity(0.5))),
|
||||
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(15), borderSide: const BorderSide(color: colorAzul, width: 2)),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -330,7 +275,7 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
||||
Navigator.pop(context);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Domicilio agregado'), backgroundColor: colorAzul, duration: const Duration(seconds: 2)),
|
||||
SnackBar(content: Text('Domicilio agregado'), backgroundColor: colorAzul),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -355,95 +300,79 @@ class _DomiciliosViewState extends State<DomiciliosView> {
|
||||
);
|
||||
}
|
||||
|
||||
void _navegarA(int index) {
|
||||
if (index == 1) {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const MainScreen()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
|
||||
decoration: const BoxDecoration(
|
||||
color: colorAzul,
|
||||
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20)),
|
||||
),
|
||||
child: const Text('Domicilios', style: TextStyle(color: Colors.white, fontSize: 28, fontWeight: FontWeight.bold), textAlign: TextAlign.center),
|
||||
return SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
|
||||
decoration: const BoxDecoration(
|
||||
color: colorAzul,
|
||||
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20)),
|
||||
),
|
||||
Expanded(
|
||||
child: _isLoading
|
||||
? const Center(child: CircularProgressIndicator(color: colorAzul))
|
||||
: domicilios.isEmpty
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.home_outlined, size: 100, color: Colors.grey.withOpacity(0.5)),
|
||||
const SizedBox(height: 20),
|
||||
Text('No hay domicilios', style: TextStyle(fontSize: 18, color: Colors.grey.withOpacity(0.7))),
|
||||
const SizedBox(height: 10),
|
||||
Text('Toca el botón + para agregar', style: TextStyle(fontSize: 14, color: Colors.grey.withOpacity(0.5))),
|
||||
],
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.all(20),
|
||||
itemCount: domicilios.length,
|
||||
itemBuilder: (context, index) {
|
||||
final d = domicilios[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 20),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.black, width: 4),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.home_outlined, size: 60),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(d.nombre, style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
|
||||
Text(d.direccionCompleta, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
Text('📍 ${d.latitud.toStringAsFixed(4)}, ${d.longitud.toStringAsFixed(4)}', style: TextStyle(fontSize: 12, color: Colors.grey[600])),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(onPressed: () => _eliminarDomicilio(index), icon: const Icon(Icons.delete_outline, size: 40), color: Colors.red),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Domicilios', style: TextStyle(color: Colors.white, fontSize: 28, fontWeight: FontWeight.bold), textAlign: TextAlign.center),
|
||||
),
|
||||
Expanded(
|
||||
child: _isLoading
|
||||
? const Center(child: CircularProgressIndicator(color: colorAzul))
|
||||
: domicilios.isEmpty
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.home_outlined, size: 100, color: Colors.grey.withOpacity(0.5)),
|
||||
const SizedBox(height: 20),
|
||||
Text('No hay domicilios', style: TextStyle(fontSize: 18, color: Colors.grey.withOpacity(0.7))),
|
||||
const SizedBox(height: 10),
|
||||
Text('Toca el botón + para agregar', style: TextStyle(fontSize: 14, color: Colors.grey.withOpacity(0.5))),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: _isLoadingLocation
|
||||
? Container(width: double.infinity, height: 100, decoration: BoxDecoration(color: colorAzul, borderRadius: BorderRadius.circular(20)), child: const Center(child: CircularProgressIndicator(color: Colors.white)))
|
||||
: GestureDetector(
|
||||
onTap: _obtenerUbicacionYAgregar,
|
||||
child: Container(width: double.infinity, height: 100, decoration: BoxDecoration(color: colorAzul, borderRadius: BorderRadius.circular(20)), child: const Icon(Icons.add, color: Colors.white, size: 80)),
|
||||
),
|
||||
itemCount: domicilios.length,
|
||||
itemBuilder: (context, index) {
|
||||
final d = domicilios[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 20),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 4), borderRadius: BorderRadius.circular(25)),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.home_outlined, size: 60),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(d.nombre, style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
|
||||
Text(d.direccionCompleta, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
Text('📍 ${d.latitud.toStringAsFixed(4)}, ${d.longitud.toStringAsFixed(4)}', style: TextStyle(fontSize: 12, color: Colors.grey[600])),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(onPressed: () => _eliminarDomicilio(index), icon: const Icon(Icons.delete_outline, size: 40), color: Colors.red),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: _isLoadingLocation
|
||||
? Container(width: double.infinity, height: 100, decoration: BoxDecoration(color: colorAzul, borderRadius: BorderRadius.circular(20)), child: const Center(child: CircularProgressIndicator(color: Colors.white)))
|
||||
: GestureDetector(
|
||||
onTap: _obtenerUbicacionYAgregar,
|
||||
child: Container(width: double.infinity, height: 100, decoration: BoxDecoration(color: colorAzul, borderRadius: BorderRadius.circular(20)), child: const Icon(Icons.add, color: Colors.white, size: 80)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: CustomNavBar(currentIndex: 0, onTap: _navegarA),
|
||||
);
|
||||
}
|
||||
}
|
||||
42
lib/src/views/home_screen.dart
Normal file
42
lib/src/views/home_screen.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
// home_screen.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'domicilios.dart';
|
||||
import 'horarios.dart';
|
||||
import 'configuracion.dart';
|
||||
import 'rutas.dart';
|
||||
import 'nav_bar.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({super.key});
|
||||
|
||||
@override
|
||||
State<HomeScreen> createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
int _currentIndex = 0; // 0: Domicilios, 1: Rutas, 2: Configuración
|
||||
|
||||
final List<Widget> _paginas = const [
|
||||
DomiciliosView(),
|
||||
HorariosView(),
|
||||
ConfiguracionView(),
|
||||
];
|
||||
|
||||
void _onNavBarTap(int index) {
|
||||
setState(() {
|
||||
_currentIndex = index;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: _paginas[_currentIndex],
|
||||
bottomNavigationBar: CustomNavBar(
|
||||
currentIndex: _currentIndex,
|
||||
onTap: _onNavBarTap,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
// login.dart - cambiar MainScreen por HomeScreen
|
||||
import 'package:flutter/material.dart';
|
||||
import 'rutas.dart';
|
||||
import 'main_screen.dart';
|
||||
import 'home_screen.dart'; // ← Importar HomeScreen
|
||||
|
||||
class LoginView extends StatelessWidget {
|
||||
const LoginView({super.key});
|
||||
@@ -27,16 +28,12 @@ class LoginView extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(30.0),
|
||||
child: Column(
|
||||
children: [
|
||||
// Campo de Correo
|
||||
_buildInput(Icons.email_outlined, 'Correo electrónico', obscureText: false),
|
||||
const SizedBox(height: 20),
|
||||
// Campo de Contraseña
|
||||
_buildInput(Icons.lock_outline, 'Contraseña', obscureText: true),
|
||||
const SizedBox(height: 50),
|
||||
// Botones
|
||||
Column(
|
||||
children: [
|
||||
// Botón Iniciar Sesión
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: colorAzul,
|
||||
@@ -44,9 +41,10 @@ class LoginView extends StatelessWidget {
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
||||
),
|
||||
onPressed: () {
|
||||
// ✅ Navegar a HomeScreen
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const MainScreen()),
|
||||
MaterialPageRoute(builder: (context) => const HomeScreen()),
|
||||
);
|
||||
},
|
||||
child: const Text(
|
||||
@@ -55,7 +53,6 @@ class LoginView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// Botón Crear Cuenta
|
||||
OutlinedButton(
|
||||
style: OutlinedButton.styleFrom(
|
||||
minimumSize: const Size(double.infinity, 55),
|
||||
|
||||
Reference in New Issue
Block a user