De todas las Page creadas en directorio /screens creamos un exportador de Pages Index.screens.dart.
export 'package:myapp/screens/Home.screen.dart';
export 'package:myapp/screens/Register.screen.dart';
export 'package:myapp/screens/Dashboard.screen.dart';
Creamos Routes.dart donde importamos el exportador de Pages y se Mapea para entregarse con su ruta en la funcion
getRoutes()
import 'package:myapp/screens/Index.screens.dart';
Map<String, WidgetBuilder> getRoutes() {
Map<String, WidgetBuilder> routes = Map();
routes['/'] = (_) => HomePage();
routes['/register'] = (_) => RegisterPage();
routes['/dashboard'] = (_) => DashboardPage();
return routes;
}
En main.dart importamos el Routes.dart trayendo la funcion
En MaterialApp agregamos:
- initialRoute: '/'
- routes: getRoutes() // con el mapeo de todas las rutas.
import 'package:flutter/material.dart';
import 'package:myapp/routers/Routes.dart'; // enrutador
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: getRoutes(),
);
}
}
Top comments (0)