RouteWidget class

Widget use to define sub routes or just for better organization or add custom transition to a particular route.

For example let's take this routes

 final myNavigator = NavigationBuilder.create(
   routes: {
     '/': (_) => HomePage(),
     '/Page1': (_) => Page1(),
     '/Page1/:id': (data) => Page1(id: data.pathParam['id']),
     '/Page1/page12': (_) => Page12(),
   },
 );

The above routes definition can be written like this:

 final myNavigator = NavigationBuilder.create(
   routes: {
     '/': (_) => HomePage(),
     '/Page1': (_) => RouteWidget(
           routes: {
             '/': (_) => Page1(),
             '/:id': (data) => Page1(id: data.pathParam['id']),
             '/page12': (_) => Page12(),
           },
         )
   },
 );

You can also use the builder property to wrap the route outlet widget inside an other widget.

 final myNavigator = NavigationBuilder.create(
   routes: {
     '/': (_) => HomePage(),
     '/Page1': (_) => RouteWidget(
           // Inside widget tree, you can get the router outlet widget using
           // `context.routerOutlet`
           builder: (routeOutlet) {
              // If you extract this Scaffold to a Widget class, you do not
              // need to use the Builder widget
             return Scaffold(
               appBar: AppBar(
                 title: OnReactive( // It reactive to routeData
                   () => Builder( // Needed only to get a child BuildContext
                     builder: (context) {
                       final location = context.routeData.location;
                       return Text('Routing to: $location');
                     },
                   ),
                 ),
               ),
               body: routeOutlet,
             );
           },
           routes: {
             '/': (_) => Page1(),
             '/:id': (data) => Page1(id: data.pathParam['id']),
             '/page12': (_) => Page12(),
           },
         )
   },
 );

Inside widget tree, you can get the router outlet widget using context.routerOutlet

RouteWidget can be just used to add custom page transition animation.

In the following example Page1 will be animated using the custom definition, whereas all other pages will use the default animation.

 final myNavigator = NavigationBuilder.create(
   // Default transition
   transitionDuration: RM.transitions.leftToRight(),
   routes: {
     '/': (_) => HomePage(),
     '/Page1': (_) => RouteWidget(
           builder: (_) => Page1(),
           // You can use one of the predefined transitions
           transitionsBuilder: (context, animation, secondAnimation, child) {
             // Custom transition implementation
             return ...;
           },
         ),
     '/page2': (_) => Page2(),
   },
 );

See Also RouteData and NavigationBuilder

Inheritance

Constructors

RouteWidget({Widget builder(Widget routerOutlet)?, Map<String, Widget Function(RouteData data)> routes = const {}, Widget transitionsBuilder(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child)?, bool? delegateImplyLeadingToParent})
Widget use to define sub routes or just for better organization or add custom transition to a particular route.

Properties

builder Widget Function(Widget routerOutlet)?
Used to wrap the the router outlet widget inside another widget.
final
delegateImplyLeadingToParent bool?
Weather to delegate the ImplyLeading used in Scaffold to parent route
final
hashCode int
The hash code for this object.
no setterinherited
isInitialized List
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
route Widget
latefinal
routeLocation String
latefinal
routePath String
latefinal
routePathResolver → ResolvePathRouteUtil
latefinal
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
transitionsBuilder Widget Function(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child)?
Define a transition builder to be used for the sub route.
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
copyWith(Widget builder(Widget child)?) RouteWidget
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
initialize() Map<String, RouteSettingsWithChildAndData>?
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited