Me encuentro realizando unas practicas con go_router y estoy intentando utilizar BottomNavigationWidget para navegar entre diferentes vistas pero me estoy encontrando con un problema y es que almomento de ejecutar la aplicacion en debug funciona medianamente bien, pero si utilizo la app descargada no navega hacia ningun lado, este es el main:
import 'package:flutter/material.dart';
import 'config/app_router.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
debugShowCheckedModeBanner: false,
theme: ThemeData(useMaterial3: true),
routerConfig: router,
);
}
}
Estas son mis rutas:
import 'package:bops_app_v3/screens/add_screen.dart';
import 'package:bops_app_v3/screens/home_screen.dart';
import 'package:bops_app_v3/screens/product_screen.dart';
import 'package:bops_app_v3/screens/profile_screen.dart';
import 'package:go_router/go_router.dart';
final router = GoRouter(routes: [
GoRoute(
path: '/',
builder: (context, state) => const HomeScreen(),
),
GoRoute(
path: '/product',
builder: (context, state) => const ProductScreen(),
),
GoRoute(
path: '/add',
builder: (context, state) => const AddScreen(),
),
GoRoute(
path: '/profile',
builder: (context, state) => const ProfileScreen(),
),
]);
Este es mi BottomNavigationWidget:
import 'package:bops_app_v3/config/app_router.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
class BottomNavigationWidget extends StatelessWidget {
const BottomNavigationWidget({super.key});
@override
Widget build(BuildContext context) {
return BottomNavigationBar(
selectedItemColor: Colors.blue,
unselectedItemColor: Colors.black,
onTap: (index) {
switch (index) {
case 0:
context.go('/');
break;
case 1:
router.go('/product');
break;
case 2:
context.go('/add');
break;
case 3:
context.go('/profile');
break;
}
},
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home_outlined), label: 'Home'),
BottomNavigationBarItem(
icon: Icon(Icons.production_quantity_limits_outlined),
label: 'Product'),
BottomNavigationBarItem(icon: Icon(Icons.add_outlined), label: 'Add'),
BottomNavigationBarItem(
icon: Icon(Icons.person_2_outlined), label: 'Profile'),
],
);
}
}
Y estas son mis vistas, todas son iguales solo cambia el body:
import 'package:bops_app_v3/widget/botton_navegation_widget.dart';
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: const Text('Home screen'),
bottomNavigationBar: const BottomNavigationWidget(),
);
}
}