Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
6a434ab9
Unverified
Commit
6a434ab9
authored
Oct 22, 2020
by
Ian Hickson
Committed by
GitHub
Oct 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix grammar and writing style for some of the Router documentation (#68513)
parent
dcc8ced8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
109 deletions
+101
-109
router.dart
packages/flutter/lib/src/widgets/router.dart
+97
-103
router_test.dart
packages/flutter/test/widgets/router_test.dart
+4
-6
No files found.
packages/flutter/lib/src/widgets/router.dart
View file @
6a434ab9
...
@@ -27,9 +27,11 @@ import 'navigator.dart';
...
@@ -27,9 +27,11 @@ import 'navigator.dart';
/// these information and navigates accordingly.
/// these information and navigates accordingly.
///
///
/// The latter case should only happen in a web application where the [Router]
/// The latter case should only happen in a web application where the [Router]
/// reports route change back to web engine.
/// reports route change
s
back to web engine.
class
RouteInformation
{
class
RouteInformation
{
/// Creates a route information.
/// Creates a route information object.
///
/// The arguments may be null.
const
RouteInformation
({
this
.
location
,
this
.
state
});
const
RouteInformation
({
this
.
location
,
this
.
state
});
/// The location of the application.
/// The location of the application.
...
@@ -42,15 +44,16 @@ class RouteInformation {
...
@@ -42,15 +44,16 @@ class RouteInformation {
/// The state of the application in the [location].
/// The state of the application in the [location].
///
///
/// The app can have different states even in the same location. For example
/// The app can have different states even in the same location. For example
,
/// the text inside a [TextField] or the scroll position in a [ScrollView]
,
/// the text inside a [TextField] or the scroll position in a [ScrollView]
.
///
t
hese widget states can be stored in the [state].
///
T
hese widget states can be stored in the [state].
///
///
/// It's only used in the web application currently. In a web application,
/// Currently, this information is only used by Flutter on the web:
/// this property is stored into browser history entry when the [Router]
/// the data is stored in the browser history entry when the
/// report this route information back to the web engine through the
/// [Router] reports this route information back to the web engine
/// [PlatformRouteInformationProvider], so we can get the url along with state
/// through the [PlatformRouteInformationProvider]. The information
/// back when the user click the forward or backward buttons.
/// is then passed back, along with the [location], when the user
/// clicks the back or forward buttons.
///
///
/// The state must be serializable.
/// The state must be serializable.
final
Object
?
state
;
final
Object
?
state
;
...
@@ -64,31 +67,29 @@ class RouteInformation {
...
@@ -64,31 +67,29 @@ class RouteInformation {
/// button), parses route information into data of type `T`, and then converts
/// button), parses route information into data of type `T`, and then converts
/// that data into [Page] objects that it passes to a [Navigator].
/// that data into [Page] objects that it passes to a [Navigator].
///
///
/// Additionally, every single part of that previous sentence can be overridden
/// Each part of this process can be overridden and configured as desired.
/// and configured as desired.
///
///
/// The [routeInformationProvider] can be overridden to change how the name of
/// The [routeInformationProvider] can be overridden to change how the name of
/// the route is obtained.
the [RouteInformationProvider.value] when
the
/// the route is obtained.
The [RouteInformationProvider.value] is used as
the
///
[Router] is first created is used as the initial route, and subsequent
///
initial route when the [Router] is first created. Subsequent notifications
///
notifications from the [RouteInformationProvider] to its listeners are
///
from the [RouteInformationProvider] to its listeners are treated as
///
treated as
notifications that the route information has changed.
/// notifications that the route information has changed.
///
///
/// The [backButtonDispatcher] can be overridden to change how back button
/// The [backButtonDispatcher] can be overridden to change how back button
/// notifications are received. This must be a [BackButtonDispatcher], which is
/// notifications are received. This must be a [BackButtonDispatcher], which is
/// an object where callbacks can be registered, and which can be chained
/// an object where callbacks can be registered, and which can be chained so
/// so that back button presses are delegated to subsidiary routers. The
/// that back button presses are delegated to subsidiary routers. The callbacks
/// callbacks are invoked to indicate that the user is trying to close the
/// are invoked to indicate that the user is trying to close the current route
/// current route (by pressing the system back button); the [Router] ensures
/// (by pressing the system back button); the [Router] ensures that when this
/// that when this callback is invoked, the message is passed to the
/// callback is invoked, the message is passed to the [routerDelegate] and its
/// [routerDelegate] and its result is provided back to the
/// result is provided back to the [backButtonDispatcher]. Some platforms don't
/// [backButtonDispatcher]. Some platforms don't have back buttons and on those
/// have back buttons (e.g. iOS and desktop platforms); on those platforms this
/// platforms it is completely normal that this notification is never sent. The
/// notification is never sent. Typically, the [backButtonDispatcher] for the
/// common [backButtonDispatcher] for root router is an instance of
/// root router is an instance of [RootBackButtonDispatcher], which uses a
/// [RootBackButtonDispatcher], which uses a [WidgetsBindingObserver] to listen
/// [WidgetsBindingObserver] to listen to the `popRoute` notifications from
/// to the `popRoute` notifications from [SystemChannels.navigation]. A
/// [SystemChannels.navigation]. Nested [Router]s typically use a
/// common alternative is [ChildBackButtonDispatcher], which must be provided
/// [ChildBackButtonDispatcher], which must be provided the
/// the [BackButtonDispatcher] of its ancestor [Router] (available via
/// [BackButtonDispatcher] of its ancestor [Router] (available via [Router.of]).
/// [Router.of]).
///
///
/// The [routeInformationParser] can be overridden to change how names obtained
/// The [routeInformationParser] can be overridden to change how names obtained
/// from the [routeInformationProvider] are interpreted. It must implement the
/// from the [routeInformationProvider] are interpreted. It must implement the
...
@@ -160,7 +161,9 @@ class RouteInformation {
...
@@ -160,7 +161,9 @@ class RouteInformation {
/// its needs.
/// its needs.
///
///
/// An application might have no [Router] widgets if it has only one "screen",
/// An application might have no [Router] widgets if it has only one "screen",
/// or if the facilities provided by [Navigator] are sufficient.
/// or if the facilities provided by [Navigator] are sufficient. This is common
/// for desktop applications, where subsidiary "screens" are represented using
/// different windows rather than changing the active interface.
///
///
/// A particularly elaborate application might have multiple [Router] widgets,
/// A particularly elaborate application might have multiple [Router] widgets,
/// in a tree configuration, with the first handling the entire route parsing
/// in a tree configuration, with the first handling the entire route parsing
...
@@ -172,68 +175,63 @@ class RouteInformation {
...
@@ -172,68 +175,63 @@ class RouteInformation {
///
///
/// ## URL updates for web applications
/// ## URL updates for web applications
///
///
/// In the web platform, it is important to keeps the URL up to date with the
/// In the web platform, keeping the URL in the browser's location bar up to
/// app state. This ensures the browser constructs its history entry
/// date with the application state ensures that the browser constructs its
/// correctly so that its forward and backward buttons continue to work.
/// history entry correctly, allowing its back and forward buttons to function
///
/// as the user expects.
/// If the [routeInformationProvider] is a [PlatformRouteInformationProvider]
/// and a app state change leads to [Router] rebuilds, the [Router] will detect
/// such a event and retrieve the new route information from the
/// [RouterDelegate.currentConfiguration] and the
/// [RouteInformationParser.restoreRouteInformation]. If the location in the
/// new route information is different from the current location, the router
/// sends the new route information to the engine through the
/// [PlatformRouteInformationProvider.routerReportsNewRouteInformation].
///
///
/// By Providing implementations of these two methods in the subclasses and using
/// If an app state change leads to the [Router] rebuilding, the [Router] will
/// the [PlatformRouteInformationProvider], you can enable the [Router] widget to
/// retrieve the new route information from the [routerDelegate]'s
/// update the URL in the browser automatically.
/// [RouterDelegate.currentConfiguration] method and the
/// [routeInformationParser]'s [RouteInformationParser.restoreRouteInformation]
/// method. If the location in the new route information is different from the
/// current location, the router sends the new route information to the
/// [routeInformationProvider]'s
/// [RouteInformationProvider.routerReportsNewRouteInformation] method. That
/// method as implemented in [PlatformRouteInformationProvider] uses
/// [SystemNavigator.routeInformationUpdated] to notify the engine, and through
/// that the browser, of the new URL.
///
///
///
You can force the [Router] to report the new route information back
to the
///
One can force the [Router] to report new route information
to the
///
engine even if the [RouteInformation.location] has not changed. By calling
///
[routeInformationProvider] (and thus the browser) even if the
///
the [Router.navigate], the [Router] will be forced to report the route
///
[RouteInformation.location] has not changed by calling the [Router.navigate]
///
information back to the engine after running the callback. This is useful
///
method with a callback that performs the state change. This allows one to
///
when you want to support the browser backward and forward buttons without
///
support the browser's back and forward buttons without changing the URL. For
///
changing the URL. For example, the scroll position of a scroll view may b
e
///
example, the scroll position of a scroll view may be saved in th
e
///
saved in the [RouteInformation.state]. If you use the [Router.navigate] to
///
[RouteInformation.state]. Using [Router.navigate] to update the scroll
///
update the scroll position, the browser will create a new history entry with
///
position causes the browser to create a new history entry with the
///
the [RouteInformation.state] that stores the new scroll position. when the
///
[RouteInformation.state] that stores this new scroll position. When the user
///
users click the backward button, the browser will go back to previous scroll
///
clicks the back button, the app will go back to the previous scroll position
///
position without changing the url
bar.
///
without changing the URL in the location
bar.
///
///
/// You can also force the [Router] to ignore a one time route information
/// One can also force the [Router] to ignore application state changes by
/// update by providing a one time app state update in a callback and pass it
/// making those changes during a callback passed to [Router.neglect]. The
/// into the [Router.neglect]. The [Router] will not report any route
/// [Router] will not report any route information even if it detects location
/// information even if it detects location change as a result of running the
/// change as a result of running the callback.
/// callback. This is particularly useful when you don't want the browser to
/// create a browser history entry for this app state update.
///
///
/// You can also choose to opt out of URL updates entirely. Simply ignore the
/// To opt out of URL updates entirely, pass null for [routeInformationProvider]
/// [RouterDelegate.currentConfiguration] and the
/// and [routeInformationParser]. This is not recommended in general, but may be
/// [RouteInformationParser.restoreRouteInformation] without providing the
/// appropriate in the following cases:
/// implementations will prevent the [Router] from reporting the URL back to the
/// web engine. This is not recommended in general, but You may decide to opt
/// out in these cases:
///
///
/// *
If you are not writing a web application
.
/// *
The application does not target the web platform
.
///
///
/// *
If you have multiple router widgets in your app, then only one router
/// *
There are multiple router widgets in the application. Only one [Router]
/// widget should update the URL (
Usu
ally the top-most one created by the
/// widget should update the URL (
typic
ally the top-most one created by the
/// [WidgetsApp.router]
/[MaterialApp.router]/
[CupertinoApp.router]).
/// [WidgetsApp.router]
, [MaterialApp.router], or
[CupertinoApp.router]).
///
///
/// *
If your app does not care about the in-app navigation using the browser's
/// *
The application does not need to implemenent in-app navigation using the
///
forward and back
ward buttons.
///
browser's back and for
ward buttons.
///
///
///
Otherwise, we strongly recommend implementing
the
///
In other cases, it is strongly recommended to implement
the
/// [RouterDelegate.currentConfiguration] and
the
/// [RouterDelegate.currentConfiguration] and
/// [RouteInformationParser.restoreRouteInformation]
to provide
optimal
/// [RouteInformationParser.restoreRouteInformation]
APIs to provide an
optimal
/// user experience
in the web application
.
/// user experience
when running on the web platform
.
class
Router
<
T
>
extends
StatefulWidget
{
class
Router
<
T
>
extends
StatefulWidget
{
/// Creates a router.
/// Creates a router.
///
///
/// The [routeInformationProvider] and [routeInformationParser] can be null if this
/// The [routeInformationProvider] and [routeInformationParser] can be null if this
/// router does not depend on route information. A common example is a sub router
/// router does not depend on route information. A common example is a sub router
/// that builds its content completely
relies
on the app state.
/// that builds its content completely
based
on the app state.
///
///
/// If the [routeInformationProvider] is not null, the [routeInformationParser] must
/// If the [routeInformationProvider] is not null, the [routeInformationParser] must
/// also not be null.
/// also not be null.
...
@@ -247,8 +245,8 @@ class Router<T> extends StatefulWidget {
...
@@ -247,8 +245,8 @@ class Router<T> extends StatefulWidget {
this
.
backButtonDispatcher
,
this
.
backButtonDispatcher
,
})
:
assert
(
})
:
assert
(
(
routeInformationProvider
==
null
)
==
(
routeInformationParser
==
null
),
(
routeInformationProvider
==
null
)
==
(
routeInformationParser
==
null
),
'
You must provide both routeInformationProvider and routeInformationParser
'
'
Both routeInformationProvider and routeInformationParser must be provided
'
'if this router parses route information. Other
iw
se, they should both '
'if this router parses route information. Other
wi
se, they should both '
'be null.'
'be null.'
),
),
assert
(
routerDelegate
!=
null
),
assert
(
routerDelegate
!=
null
),
...
@@ -282,8 +280,8 @@ class Router<T> extends StatefulWidget {
...
@@ -282,8 +280,8 @@ class Router<T> extends StatefulWidget {
/// builds a navigating widget for the [Router].
/// builds a navigating widget for the [Router].
///
///
/// It is also the primary respondent for the [backButtonDispatcher]. The
/// It is also the primary respondent for the [backButtonDispatcher]. The
/// [Router] relies on
the [RouterDelegate.popRoute] to handles
the back
/// [Router] relies on
[RouterDelegate.popRoute] to handle
the back
/// button
intends
.
/// button.
///
///
/// If the [RouterDelegate.currentConfiguration] returns a non-null object,
/// If the [RouterDelegate.currentConfiguration] returns a non-null object,
/// this [Router] will opt for URL updates.
/// this [Router] will opt for URL updates.
...
@@ -297,11 +295,9 @@ class Router<T> extends StatefulWidget {
...
@@ -297,11 +295,9 @@ class Router<T> extends StatefulWidget {
/// Retrieves the immediate [Router] ancestor from the given context.
/// Retrieves the immediate [Router] ancestor from the given context.
///
///
/// Use this method when you need to access the delegates in the [Router].
/// This method provides access to the delegates in the [Router]. For example,
/// For example, you need to access the [backButtonDispatcher] of the parent
/// this can be used to access the [backButtonDispatcher] of the parent router
/// router to create a [ChildBackButtonDispatcher] for a nested router.
/// when creating a [ChildBackButtonDispatcher] for a nested [Router].
/// Another use case may be updating the value in [routeInformationProvider]
/// to navigate to a new route.
static
Router
<
dynamic
>?
of
(
BuildContext
context
,
{
bool
nullOk
=
false
})
{
static
Router
<
dynamic
>?
of
(
BuildContext
context
,
{
bool
nullOk
=
false
})
{
final
_RouterScope
?
scope
=
context
.
dependOnInheritedWidgetOfExactType
<
_RouterScope
>();
final
_RouterScope
?
scope
=
context
.
dependOnInheritedWidgetOfExactType
<
_RouterScope
>();
assert
(()
{
assert
(()
{
...
@@ -1011,13 +1007,11 @@ abstract class RouteInformationParser<T> {
...
@@ -1011,13 +1007,11 @@ abstract class RouteInformationParser<T> {
/// Restore the route information from the given configuration.
/// Restore the route information from the given configuration.
///
///
/// This is not required if you do not opt for the route information reporting
/// This may return null, in which case the browser history will not be updated.
/// , which is used for updating browser history for the web application. If
/// See [Router]'s documentation for details.
/// you decides to opt in, you must also overrides this method to return a
/// route information.
///
///
///
In practice, t
he [parseRouteInformation] method must produce an equivalent
///
T
he [parseRouteInformation] method must produce an equivalent
/// configuration when passed this method's return value
/// configuration when passed this method's return value
.
RouteInformation
?
restoreRouteInformation
(
T
configuration
)
=>
null
;
RouteInformation
?
restoreRouteInformation
(
T
configuration
)
=>
null
;
}
}
...
@@ -1025,21 +1019,21 @@ abstract class RouteInformationParser<T> {
...
@@ -1025,21 +1019,21 @@ abstract class RouteInformationParser<T> {
/// navigating widget.
/// navigating widget.
///
///
/// This delegate is the core piece of the [Router] widget. It responds to
/// This delegate is the core piece of the [Router] widget. It responds to
/// push route and pop route intent from the engine and notifies the [Router]
/// push route and pop route intent
s
from the engine and notifies the [Router]
/// to rebuild. It also act as a builder for the [Router] widget and builds a
/// to rebuild. It also act
s
as a builder for the [Router] widget and builds a
/// navigating widget, typically a [Navigator], when the [Router] widget
/// navigating widget, typically a [Navigator], when the [Router] widget
/// builds.
/// builds.
///
///
/// When engine pushes a new route, the route information is parsed by the
/// When
the
engine pushes a new route, the route information is parsed by the
/// [RouteInformationParser] to produce a configuration of type T. The router
/// [RouteInformationParser] to produce a configuration of type T. The router
/// delegate receives the configuration through [setInitialRoutePath] or
/// delegate receives the configuration through [setInitialRoutePath] or
/// [setNewRoutePath] to configure itself and builds the latest navigating
/// [setNewRoutePath] to configure itself and builds the latest navigating
/// widget
upon asked
.
/// widget
when asked ([build])
.
///
///
/// When implementing subclass
, consider defining a listenable app state
to be
/// When implementing subclass
es, consider defining a [Listenable] app state object
to be
/// used for building the navigating widget. The router delegate
sh
ould update
/// used for building the navigating widget. The router delegate
w
ould update
/// the app state accordingly and notify
the listener know
the app state has
/// the app state accordingly and notify
its own listeners when
the app state has
/// changed when it receive route related engine intents (e.g.
/// changed
and
when it receive route related engine intents (e.g.
/// [setNewRoutePath], [setInitialRoutePath], or [popRoute]).
/// [setNewRoutePath], [setInitialRoutePath], or [popRoute]).
///
///
/// All subclass must implement [setNewRoutePath], [popRoute], and [build].
/// All subclass must implement [setNewRoutePath], [popRoute], and [build].
...
...
packages/flutter/test/widgets/router_test.dart
View file @
6a434ab9
...
@@ -155,9 +155,8 @@ void main() {
...
@@ -155,9 +155,8 @@ void main() {
}
on
AssertionError
catch
(
e
)
{
}
on
AssertionError
catch
(
e
)
{
expect
(
expect
(
e
.
message
,
e
.
message
,
'You must provide both routeInformationProvider and '
'Both routeInformationProvider and routeInformationParser must be provided if this router '
'routeInformationParser if this router parses route information. '
'parses route information. Otherwise, they should both be null.'
'Otheriwse, they should both be null.'
);
);
}
}
});
});
...
@@ -175,9 +174,8 @@ void main() {
...
@@ -175,9 +174,8 @@ void main() {
}
on
AssertionError
catch
(
e
)
{
}
on
AssertionError
catch
(
e
)
{
expect
(
expect
(
e
.
message
,
e
.
message
,
'You must provide both routeInformationProvider and '
'Both routeInformationProvider and routeInformationParser must be provided if this router '
'routeInformationParser if this router parses route information. '
'parses route information. Otherwise, they should both be null.'
'Otheriwse, they should both be null.'
);
);
}
}
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment