nuvigator 0.1.0+1
nuvigator: ^0.1.0+1 copied to clipboard
A powerful and strongly typed routing abstraction over Flutter navigator, providing some new features and an easy way to define routers with code generation.
Nuvigator #
Routing and Navigation package.
What #
This package aims to provide a powerful routing abstraction over Flutter Navigators. Using a most declarative and concise approach you will be able to model complex navigation flows without needing to worry about several tricky behaviours that the framework will handle for you.
Below you will find a description of the main components of this frameworks, and how you can use they in your project.
Main Concepts #
Basic usage
class MyRouter extends BaseRouter {
@override
Map<String, Screen> get screensMap => {
'MyScreenRouteName': Screen(
builder: (screenContext) => MyScreen(screenContext),
),
};
}
final router = GlobalRouter(baseRouter: MyRouter());
Widget build(BuildContext context) {
return MaterialApp(
builder: Nuvigator(
router: router,
screenType: materialScreenType,
initialRoute: 'MyScreenRouteName',
),
);
}
Nuvigator #
Nuvigator
is a custom Navigator
, it behaves just like a normal Navigator
, but with several
custom improvements and features. It is engineered specially to work under nested scenarios, where
you can have several Flows one inside another. Nuvigator
will be your main interface to interact with navigation, and it can be easily fetched from
the context, just like a normal Navigator
, ie: Nuvigator.of(context)
.
Each Nuvigator
should have a Router
. The Router
acts just like the routing controller. While
the Nuvigator
will be responsible for visualization, widget render and state keeping. The Router
will be Pure class that will be responsible to provide elements to be presented and managed by the Nuvigator.
ScreenRoute and FlowRoute #
Envelopes a widget that is going to be presented as a Screen by a Navigator. The Screen contains a ScreenBuilder function, and some attributes, like transition type, that are going to be used to generate a route properly.
Screen Options:
- builder
- screenType
- deepLink
- wrapperFn
BaseRouter #
Basic Usage:
class ChatRouter extends BaseRouter {
@override
Map<String, ScreenRoute> get screensMap => {
'home': ScreenRoute(
builder: (context) => ChatHomeScreen(context),
screenType: materialScreenType,
deepLink: '/myGroup/test/',
),
};
}
Options:
screensMap
A Map<String, Screen> that contains the mapping between RouteNames and Screens.
deepLinkPrefix
A String, that will be used as prefix for every entry key at the deepLinksMaps
.
screenWrapper
A function that will receives a ScreenContext and a child Widget. Should return a new Widget that wraps this child Widget. The Wrapper will be applied to all Screens in this Router. (this function runs one time for each screen, and not one time for the entire Router).
routers
Routers to be grouped and checked if this router does not match any screen.