route_map

Last updated:

0 purchases

route_map Image
route_map Images
Add to Cart

Description:

route map

Route Map #
Generate route paths map for Flutter Navigator 2 using annotation.






README Translation #

English
Türkçe

Table of Contents #

Route Map

README Translation
Table of Contents
Installation
Setup
Run the generator
Problems with the generation?
Support the Library



Tutorial #

Bottom navigation bar


#
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:
copied to clipboard
Setup #

First, define Route Generator with RouteMapInit annotation.

import 'route_map.config.dart';

@RouteMapInit()
Route? onGenerateRoute(RouteSettings routeSettings) => $onGenerateRoute(routeSettings);
copied to clipboard

Redirection changes the location to a new one based on application state. For example, redirection can be used to display a sign-in screen if the user is not logged in.

import 'route_map.config.dart';

@RouteMapInit()
Route? onGenerateRoute(RouteSettings routeSettings) => $onGenerateRoute(routeSettings,redirect:(path){
bool isLogin = false;
if(isLogin && RouteMaps.homePage == path){
return RouteMap.login;
}
return null;
});
copied to clipboard

Define the route builder in the MaterialApp widget

MaterialApp(
initialRoute: RouteMaps.splash, // defining the initial page
onGenerateRoute: onGenerateRoute
);
copied to clipboard

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 {}

@RouteMap(name: "/detail", path:"/detail/:id/:name")
class DetailPage extends StatefulWidget {}
copied to clipboard

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.

DetailPageRoute(id: "0",name: "push").push(context);

DetailPageRoute(id: "0",name: "push").popAndPush(context);
copied to clipboard

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"});
copied to clipboard

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"];


copied to clipboard

@RouteMapArg() attribute should be used for custom model.

@RouteMapArg()
class CustomModel {
String name;
CustomModel({required this.name});
}
copied to clipboard

Customized builder is available. For example, you might want to wrap your page with ChangeNotifierProvider.

Widget homeBuilder(Widget child) {
return ChangeNotifierProvider(
create: (_) => HomeViewModel(),
child: child,
);
}

@RouteMap(name: "home", builder: homeBuilder)
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);

@override
State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
copied to clipboard
I need help. #
URL-based page redirection is still experimental. There are issues regarding type conversions, and it hasn't been thoroughly tested yet.
I need assistance with type conversions in URL-based page redirection. It supports int, double, string, and bool.
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
copied to clipboard
if you want the generator to run one time and exits use
flutter packages pub run build_runner build --delete-conflicting-outputs
copied to clipboard
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
copied to clipboard
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.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.