StandardPageFactory<T extends StandardPage<R> , R extends Object?> class
base
Factory class for StandardPage to be set in the page property of StandardMaterialApp or StandardCupertinoApp.
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.
Regular expression restrictions
When defining regular expressions for deep links, the following rules apply:
-
Only named capture groups are allowed for value extraction. Use the
(?<name>...)syntax to capture values. -
Numbered capture groups are prohibited. Patterns such as
(...)that allow access viamatch.group(1)must not be used. -
Non-capturing and conditional group constructs that do not capture values are allowed, including:
- Non-capturing groups:
(?:...) - Lookaheads:
(?=...),(?!...) - Lookbehinds:
(?<=...),(?<!...)
- Non-capturing groups:
These restrictions require all captured values to be defined using
named capture groups via match.namedGroup(...).
This avoids relying on the positional order of capture groups, which can change when regular expressions are generated or composed across parent and child links, and prevents subtle breakage caused by such changes.
example:
StandardPageFactory<PageC, TestPageData>(
create: (data) => PageC(),
links: {
r'page/(?<id>\d+)': (match, uri) => TestPageData(
id: int.parse(match.namedGroup('id')!),
category: uri.queryParameters['category'],
),
},
linkGenerator: (pageData) => 'page/${pageData.id}',
)
StandardChildPageFactory can be used to define child pages that can be navigated to from this page.
StandardPageWithNestedNavigatorFactory can be used to define pages with nested Navigators. This is useful, for example, when implementing applications with multiple footer menus.
- Inheritance
-
- Object
- StandardPageWithResultFactory<
T, R, void> - StandardPageFactory
- Implementers
Constructors
-
StandardPageFactory({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, LocalKey pageKey(R pageData)?, StandardPageBuilder<R, void> ? pageBuilder, R pageDataWhenNull()?, String? pageName()?, String restorationId(R pageData)?, List<StandardChildPageWithResultFactory< childPageFactories = const []})StandardPageWithResult< >Object?, Object?> , Object?, Object?, Object?> -
Create a StandardPageFactory
const
Properties
- activeFirstNestedPage → bool
-
Flag indicating whether the first page in nestedPageFactories
should always be stacked as the first page of the nested Navigator.
no setterinherited
-
Add to the deepest navigator when there are multiple nested navigators.
no setterinherited
-
anyNestedPageFactories
→ List<
StandardPageWithResultFactory< StandardPageWithResult< >Object?, Object?> , Object?, Object?> -
The list of nested pages that can be used in any nested Navigator.
no setterinherited
-
childPageFactories
→ List<
StandardChildPageWithResultFactory< StandardPageWithResult< >Object?, Object?> , Object?, Object?, Object?> -
The list of child pages that can be navigated to from this page.
finalinherited
- create → T Function(R pageData)
-
Creates the
Tpage 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
-
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
- hasChildPages → bool
-
Flag indicating whether there are child pages that can be navigated to from this page.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasNestedPages → bool
-
Flag indicating whether there are nested pages.
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.
finalinherited
-
The method for transitioning to this page from other pages.
Please refer to StandardPageNavigationMode for navigation modes.
finalinherited
-
The navigator page factory of this page, if any.
no setterinherited
-
nestedPageFactories
→ List<
StandardPageWithResultFactory< StandardPageWithResult< >Object?, Object?> , Object?, Object?> -
The list of nested pages when using nested Navigators.
no setterinherited
-
pageBuilder
→ StandardPageBuilder<
R, void> ? -
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
-
parentPageFactory
→ StandardPageWithResultFactory<
StandardPageWithResult< ?Object?, Object?> , Object?, Object?> -
The parent page factory of this page, if any.
no setterinherited
- 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
-
createParentPageData(
R pageData) → Object? -
When using child pages, specifies how to create the parent page data from the page data of this page.
inherited
-
generateLink(
Object? pageData) → String? -
Returns the deep link generated by this page for the given
pageData.inherited -
getPageKey(
Object? pageData) → LocalKey -
Get the key set for this page, as configured for this page.
inherited
-
goWithResult(
R pageData, [bool pushParentPage = false]) → Future< void> -
Navigate to the StandardPage of type
Twith the option to passpageDataduring navigation. An optionalnavigationModerepresenting the mode of StandardPageNavigationMode to use during navigation can also be provided.pushParentPageindicates whether to push the parent page when navigating to a child page. default isfalse.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