DEV Community

Miguel Ramirez
Miguel Ramirez

Posted on


flutter #2 #routes - simple

De todas las Page creadas en directorio /screens creamos un exportador de Pages Index.screens.dart.
Image description

export 'package:myapp/screens/Home.screen.dart';
export 'package:myapp/screens/Register.screen.dart';
export 'package:myapp/screens/Dashboard.screen.dart';
Enter fullscreen mode Exit fullscreen mode

Creamos Routes.dart donde importamos el exportador de Pages y se Mapea para entregarse con su ruta en la funcion


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;
Enter fullscreen mode Exit fullscreen mode

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() {

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'My App',
      debugShowCheckedModeBanner: false,
      initialRoute: '/',
      routes: getRoutes(),
Enter fullscreen mode Exit fullscreen mode


Oldest comments (0)

We are hiring! Do you want to be our Senior Platform Engineer? Forem is hiring a Senior Platform Engineer

If you're interested in ops and site reliability and capable of dipping in to our Linux stack, we'd love your help shoring up our systems!