AppRouter class

Controller to define routing for the entire app.

You can define the routing for the entire app by passing it to routerConfig in MaterialApp.router.

The controller itself can also be manipulated, and page transitions can be performed directly by executing push, replace, and pop.

It is also possible to get the AppRouter object itself with AppRouter.of.

By executing setPathUrlStrategy, it is possible to use URLs with the web hash (#) removed.

Adapters for loggers can be applied to routing in loggerAdapters.

アプリ全体のルーティングを定義するためのコントローラー。

MaterialApp.routerrouterConfigに渡すことでアプリ全体のルーティングを定義することができます。

また、このコントローラー自体を操作することが可能でpushreplacepopを実行することでページ遷移を直接行うことが可能です。

また、AppRouter.ofAppRouterのオブジェクト自体を取得することも可能です。

setPathUrlStrategyを実行することでWebのハッシュ(#)を消したURLを利用することが可能になります。

loggerAdaptersでロガー用のアダプターをルーティングに適用することができます。

final appRouter = AppRouter(
  pages: [
    ListPage.query,
    DetailPage.query,
  ]
);

void main(){
  runApp(
    const MainPage(),
  );
}

class MainPage extends StatelessWidget {
  const MainPage();

  @override
  Widget build(BuilcContext context){
    return MaterialApp.router(
      routerConfig: appRouter,
      title: "Title",
    );
  }
}

Inheritance
Implemented types
Implementers
Available Extensions

Constructors

AppRouter({UnknownRouteQueryBuilder? unknown, BootRouteQueryBuilder? boot, String? initialPath, RouteQuery? initialQuery, required List<RouteQueryBuilder> pages, List<RedirectQuery> redirect = const [], List<NavigatorObserver> observers = const [], int redirectLimit = 5, GlobalKey<NavigatorState>? navigatorKey, String? restorationScopeId, TransitionQuery? defaultTransitionQuery, bool reportsRouteUpdateToEngine = true, Widget backgroundWidget = const Scaffold(), List<LoggerAdapter> loggerAdapters = const [], bool nested = false})
Controller to define routing for the entire app.

Properties

backButtonDispatcher BackButtonDispatcher
The BackButtonDispatcher that is used to configure the Router.
final
currentQuery RouteQuery?
You can check the current RouteQuery.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
loggerAdapters List<LoggerAdapter>
Adapter to define loggers.
no setter
The navigator that the observer is observing, if any.
no setterinherited
List of NavigatorObserver currently owned by AppRouter.
no setter
pages List<RouteQueryBuilder>
List of pages currently passed to AppRouter.
no setter
routeInformationParser RouteInformationParser<RouteQuery>
The RouteInformationParser that is used to configure the Router.
no setteroverride
routeInformationProvider RouteInformationProvider?
The RouteInformationProvider that is used to configure the Router.
no setteroverride
routerDelegate RouterDelegate<RouteQuery>
The RouterDelegate that is used to configure the Router.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
canPop() bool
Checks if the page is pop-able. If true is returned, the page is popable.
clear() → void
Clears all router pages and returns to the startup state.
didPop(Route route, Route? previousRoute) → void
The Navigator popped route.
override
didPush(Route route, Route? previousRoute) → void
The Navigator pushed route.
override
didRemove(Route route, Route? previousRoute) → void
The Navigator removed route.
override
didReplace({Route? newRoute, Route? oldRoute}) → void
The Navigator replaced oldRoute with newRoute.
override
didStartUserGesture(Route route, Route? previousRoute) → void
The Navigator's routes are being moved by a user gesture.
inherited
didStopUserGesture() → void
User gesture is no longer controlling the Navigator.
inherited
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
pop<E>([E? result]) → void
Discards the current page and returns to the previous page.
popUntil<E>(bool predicate(RouteQuery query), [E? result]) → void
Keep pop until the predicate condition is true.
push<E>(RouteQuery routeQuery, [TransitionQuery? transitionQuery]) Future<E?>
Passing routeQuery will take you to a new page.
pushNamed<E>(String path, [TransitionQuery? transitionQuery]) Future<E?>
Finds a RouteQuery that matches the path in the list of pages passed to AppRouter.pages and transitions to that page.
refresh() → void
Refresh the current page.
registerPage(RouteQueryBuilder pageBuilder) → void
Register a new RouteQueryBuilder.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
replace<E>(RouteQuery routeQuery, [TransitionQuery? transitionQuery]) Future<E?>
Passing routeQuery replaces the currently displayed page with a new page.
replaceNamed<E>(String path, [TransitionQuery? transitionQuery]) Future<E?>
Finds a RouteQuery that matches the path in the list of pages passed to AppRouter.pages and replaces the currently displayed page with that page.
reset<E>([E? result]) → void
Continue to pop until the history stack runs out.
resetAndPush<E>(RouteQuery routeQuery, [TransitionQuery? transitionQuery]) Future<E?>
Keep pop until the history stack runs out, then push routeQuery.
resetAndPushNamed<E>(String path, [TransitionQuery? transitionQuery]) Future<E?>
Continue pop until the history stack runs out, then push to the RouteQuery that applies to path.
toString() String
A string representation of this object.
inherited
unregisterPage(RouteQueryBuilder pageBuilder) → void
Unregister the RouteQueryBuilder.

Operators

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

Static Methods

of(BuildContext context, {bool root = false}) AppRouter
Sets the URL strategy of your web app to using paths instead of a leading hash (#).