route_map 0.0.4 copy "route_map: ^0.0.4" to clipboard
route_map: ^0.0.4 copied to clipboard

Route Map is a convenient code generator for Navigator 2.0. Inspired by injectable.

Route Map #

Generate route paths map for Flutter Navigator 2 using annotation.

MIT License stars pub version Buy Me A Coffee

README Translation #

Table of Contents #


Installation #

dependencies:  
  # add route_map to your dependencies  
  route_map:  
  
dev_dependencies:  
  # add the generator to your dev_dependencies  
  route_map_generator:  
  # add build runner if not already added  
  build_runner:  

Setup #

  1. First, define Route Generator with RouteMapInit annotation.
import 'route_map.config.dart';

        @RouteMapInit()
        Route? onGenerateRoute(RouteSettings routeSettings) => $onGenerateRoute(routeSettings);
  1. Define the route builder in the MaterialApp widget
MaterialApp(
        initialRoute: RouteMaps.splash, // defining the initial page
        onGenerateRoute: onGenerateRoute
);
  1. Annotate your pages with @RouteMap and let the generator do the work.

Note: Use "/" to specify the root directory. To create a root-independent page, there must be no "/" at the beginning.

@RouteMap(name: "splash")
class SplashPage extends StatefulWidget {}

@RouteMap(name: "/")
class HomePage extends StatefulWidget {}

@RouteMap(name: "/search", fullScreenDialog: true)
class SearchPage extends StatefulWidget {}
  1. You can take advantage of the class object to be redirected when passing data between pages. You can use all the functions of the standart Navigator class.
DetailPage(id: "0",name: "push").push(context);

DetailPage(id: "0",name: "push").popAndPush(context);
  1. Redirection between pages using standart Navigator class

The arguments field can be used to send values during routing.

Navigator.of(context)
        .pushNamed(RouteMaps.detailPage, arguments: "value");

Navigator.of(context)
        .pushNamed(RouteMaps.detailPage, arguments: {"val1":"Easy","val2":"Route"});
  1. Reading the values with routeArgs() passed from previous screen via Navigator.
String value = context.routeArgs();

String val1 = context.routeArgs()["val1"];

String val2 = context.routeArgs()["val2"];

Run the generator #

Use the [watch] flag to watch the files' system for edits and rebuild as necessary.

flutter packages pub run build_runner watch --delete-conflicting-outputs  

if you want the generator to run one time and exits use

flutter packages pub run build_runner build --delete-conflicting-outputs  

Problems with the generation? #

Make sure you always Save your files before running the generator, if that does not work you can always try to clean and rebuild.

flutter packages pub run build_runner clean  

Support the Library #

  • You can support the library by staring it on Github && liking it on pub.dev or report any bugs you encounter.
  • Also, if you have a suggestion or think something can be implemented in a better way, open an issue and let's talk about it.
16
likes
0
pub points
63%
popularity

Publisher

verified publisheremintolgahanpolat.com

Route Map is a convenient code generator for Navigator 2.0. Inspired by injectable.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on route_map