DynamicRoutesNavigator class abstract

Let's say that your login flow requires the user to fill in their information and the form is split into 5 pages. However, some of the information in those 5 pages can also be pre-obtained through other means, which would render some of the pages in this flow unnecessary.

The solution would be to have some sort of navigator that we can just say push conditionally push some of these set of pages in some specific order.

We can begin by marking the participating page with the DynamicRoutesParticipator mixin. This would give that component access to the dynamicRoutesParticipator instance that is tied to the /// scope of the initiator page that we'll mark with the DynamicRoutesInitiator.

For the page directly before the flow:

class SomeWidget extends StatefulWidget with DynamicRoutesInitiator {
  //...some code
}

class _SomeWidgetState extends State<SomeWidget> {

  //...some code

  void onButtonPressed() {
    const isPage4Required = calculateIfPage4IsRequired();

    dynamicRoutesInitiator.initializeRoutes(
        [
          Page1(),
          Page2(),
          Page3(),
          if (isPage4Required) Page4(),
          Page5(),
        ],
        lastPageCallback: (context) {
          // Do something; maybe return to homepage.
        }
    );
  }

//...some code

}

And then, in the pages that are included in the array (the "participating" pages).

class SomeWidget extends StatefulWidget with DynamicRoutesParticipator{
  //...some code
}

class _SomeWidgetState extends State<SomeWidget> {
  void onButtonPressed() => widget.dynamicRoutesParticipator.pushNext(context);
//...build methods and whatever
}

We can dispose the DynamicRoutesInitiator instance along with the page itself by calling the initiator's dispose method in the state's dispose method. This will also dispose all DynamicRoutesParticipator instances.


@override
void dispose() {
  dynamicRoutesInitiator.dispose();

  super.dispose();
}

Implemented types
Implementers

Constructors

DynamicRoutesNavigator()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getCurrentPageIndex(Widget currentPage) int
Returns the index of the current page. The index corresponds to its position in the pages array passed to the initializeRoutes method of the initiator.
inherited
getCurrentWidgetHash() int?
Returns the page widget that belongs to the current route
inherited
getLoadedPages() List<Widget>
inherited
getProgressFromCurrentPage(Widget currentPage) int
Returns how many pages are left until the last page. 0 means it's the last page.
inherited
initializeRoutes(List<Widget> pages, {dynamic lastPageCallback(BuildContext context)?}) → void
Call this function to load a list of pages to be pushed on to the array.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
popCurrent<T>(BuildContext context, {required Widget currentPage, T? popResult}) → void
Pop the current page and all of its sub-routes.
inherited
popFor<T>(BuildContext context, int numberOfPagesToPop, {required Widget currentPage, T? popResult}) → void
You can reset the flow, eg. go back to the first Participator page, or the Initiator page with popFor.
inherited
popUntilInitiatorPage<T>(BuildContext context, {T? popResult}) → void
Pops the pages until the current navigator. Use this in the lastPageCallback to pop until the initiator page.
inherited
pushFirst<T>(BuildContext context) Future<T?>
Push the first page in the array
inherited
pushFirstThenFor<T>(BuildContext context, int numberOfPagesToPush) List<Future<T?>>
This is similar to pushFor, but is called from the initiator. Internally, we just call pushFirst first, then call pushFor. All methods of awaiting the results mentioned above apply here as well.
inherited
pushFor<T>(BuildContext context, int numberOfPagesToPush, {required Widget currentPage}) List<Future<T?>>
You can push multiple pages at once with pushFor.
inherited
pushNext<T>(BuildContext context, {required Widget currentPage}) Future<T?>
Push the next page in the array
inherited
setNavigationLogicProvider(NavigationLogicProvider navigationLogicProvider) → void
Override the current navigation logic.
inherited
toString() String
A string representation of this object.
inherited

Operators

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