StandardPageFactory<T extends StandardPage<R>, R extends Object?> class base

Factory class for StandardPage to be set in the page property of StandardMaterialApp. T is the type of the destination page, and R is the type of page data. The following source code is an example of passing StandardPageFactory to StandardMaterialApp.pages.

example:

StandardMaterialApp(
  onGenerateTitle: (context) => 'sample',
  pages: [
    StandardPageFactory<PageA, void>(
      create: (_) => PageA(),
    ),
    StandardPageFactory<PageB, PageBData>(
      create: (_) => PageB(),
    ),
  ],
);

Page navigation is generally done using context.go. You pass the type of the specified page and the page data associated with that type during navigation. For pages like PageA that do not involve data transfer, you can navigate using context.go<PageA, void>(null). For screens with PageBData class page data reception, you can navigate using context.go<PageB, PageBData>(PageBData());. For pages with PageBData class as page data, you can navigate using context.go<PageB, PageBData>(PageBData());.

There is a concept called "group" that can be configured for each page. If no group is specified, it defaults to defaultGroup. When transitioning to a group different from the current page's group, all pages other than the destination group will be removed.

You can set deep links for each page. StandardPageFactory.new's links allows you to define regular expressions for deep links to navigate to this page. Multiple configurations are possible. linkGenerator creates deep links to navigate to this page from the page data's state for this page.

example:

StandardPageFactory<PageC, DeepLinkData>(
  create: (_) => PageC(),
  links: {
    r'pageC/(\d+)' : (match, uri) => DeepLinkData(
      id: int.parse(uri.queryParameters([‘id’])!),
      message: 'this is message',
    ),
  },
  linkGenerator: (pageC) => 'pageC/${pageC.id}',
),

class DeepLinkData {
  DeepLinkData({
    required this.id,
    required this.message,
  });
  final int id;
  final String? message;
}

For each page, you can specify which page class to use as the parent page type using parentPageType. This is useful, for example, when implementing applications with multiple footer menus.

example:

StandardMaterialApp(
  onGenerateTitle: (context) => l(context, 'title'),
  pages: [
    // HomePage Menu
    StandardPageFactory<HomePage, void>(
      create: (data) => HomePage(),
    ),
    StandardPageFactory<TitlePage, void>(
      create: (data) => TitlePage(),
      parentPageType: HomePage,
    ),
    StandardPageFactory<TitleDetailsPage, void>(
      create: (data) => TitleDetailsPage(),
      parentPageType: HomePage,
    ),
    // MyPage Menu
    StandardPageFactory<MyPage, void>(
      create: (data) => MyPage(),
    ),
    StandardPageFactory<MyFavoritePage, void>(
      create: (data) => MyFavoritePage(),
      parentPageType: MyPage,
    ),
  ],
);
Inheritance
Implementers

Constructors

StandardPageFactory.new({required T create(R pageData), Map<String, R Function(RegExpMatch match, Uri uri)>? links, String linkGenerator(R pageData)?, bool groupRoot = false, String? group = defaultGroup, bool keepHistory = true, bool enableNavigationAnalytics = true, StandardPageNavigationMode navigationMode = StandardPageNavigationMode.moveToTop, LocalKey pageKey(R pageData)?, StandardPageInterface<R, void> pageBuilder(Widget child, String? name, R pageData, LocalKey pageKey, String restorationId, GlobalKey<StandardPageWithResult<R, void>> standardPageKey, StandardPageWithResultFactory<StandardPageWithResult<R, void>, R, void> factoryObject)?, R pageDataWhenNull()?, String? pageName()?, String restorationId(R pageData)?, Type? parentPageType})
Create a StandardPageFactory

Properties

create → T Function(R pageData)
Creates the T page that this factory manages.
finalinherited
dataType Type
The data type of this page.
no setterinherited
dataTypeIsNonNullable bool
Flag indicating that the type of page data set for this page is nullable.
no setterinherited
enableNavigationAnalytics bool
Flag indicating whether to enable analytics for navigation.
finalinherited
group String?
The group name used to manage multiple pages as part of the same group when they exist.
finalinherited
groupRoot bool
Flag indicating whether to set this page as the root group if a group name is specified.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
keepHistory bool
Flag indicating whether to stack this page as part of the history or not.
finalinherited
linkGenerator String Function(R pageData)?
The function to create deep links for this page. The return value must match the keys (regular expressions) passed to links and their corresponding R 'pageData' destinations.
finalinherited
The method for transitioning to this page from other pages. Please refer to StandardPageNavigationMode for navigation modes.
finalinherited
pageBuilder StandardPageInterface<R, void> Function(Widget child, String? name, R pageData, LocalKey pageKey, String restorationId, GlobalKey<StandardPageWithResult<R, void>> standardPageKey, StandardPageWithResultFactory<StandardPageWithResult<R, void>, R, void> factoryObject)?
A function for creating StandardPageInterface.
finalinherited
pageDataWhenNull → R Function()?
A function to generate a replacement value when the pageData passed during navigation is null.
finalinherited
pageName String? Function()?
The name of this page.
finalinherited
pageType Type
The page type of this page.
no setterinherited
parentPageType Type?
When using nested Navigators, specifies what the parent page Type of this child page should be.
finalinherited
restorationId String Function(R pageData)?
A function for generating a value to pass to Page.restorationId.
finalinherited
resultType Type
The result type of this page.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

Returns the deep link generated by this page given pageData.
inherited
getPageKey(Object? pageData) LocalKey
Get the key set for this page, as configured for this page.
inherited
goWithResult(R pageData, [StandardPageNavigationMode? navigationMode]) Future<void>
Navigate to the StandardPage of type T with the option to pass pageData during navigation. An optional navigationMode representing the mode of StandardPageNavigationMode to use during navigation can also be provided.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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