Unverified Commit 9430906e authored by Dan Field's avatar Dan Field Committed by GitHub

clarify widgetsapp docs (#24090)

* clarify widgetsapp docs

* Rename shadowed param, update doc

* pageContentBuilder
parent aab92447
...@@ -82,19 +82,17 @@ class WidgetsApp extends StatefulWidget { ...@@ -82,19 +82,17 @@ class WidgetsApp extends StatefulWidget {
/// _not_ contain an entry for `'/'`. Conversely, if [home] is omitted, [routes] /// _not_ contain an entry for `'/'`. Conversely, if [home] is omitted, [routes]
/// _must_ contain an entry for `'/'`. /// _must_ contain an entry for `'/'`.
/// ///
/// If [home] or [routes] are not null, then either the [pageRoutebuilder] or /// If [home] or [routes] are not null, the routing implementation needs to know how
/// the [builder] parameter is required. These parameters will be used so /// appropriately build [PageRoutes]. This can be achieved by supplying the
/// that the default routing implementation in [WidgetsApp] can wrap routes in /// [pageRouteBuilder] parameter. The [pageRouteBuilder] is used by [MaterialApp]
/// appropriate transitions. For example, [MaterialApp] will provide a /// and [CupertinoApp] to create [MaterialPageRoute]s and [CupertinoPageRoute],
/// [pageRoutebuilder] that creates Material compliant hero animations between /// respectively.
/// routes, whereas the [CupertinoApp] provides Cupertino compliant hero ///
/// animations. Other implementations can provide other custom transitions here. /// The [builder] parameter is designed to provide the ability to wrap the visible
/// /// content of the app in some other widget. It is recommended that you use [home]
/// The [builder] parameter is optional in all cases. It can be used to ensure that /// rather than [builder] if you intend to only display a single route in your app.
/// all route entries get wrapped in another widget. It is invoked during the build ///
/// phase of this widget. If it is specified, /// [WidgetsApp] is also possible to provide a custom implementation of routing via the
///
/// It is also possible to provide a custom implementation of routing via the
/// [onGeneratedRoute] and [onUnknownRoute] parameters. These parameters correspond /// [onGeneratedRoute] and [onUnknownRoute] parameters. These parameters correspond
/// to [Navigator.onGenerateRoute] and [Navigator.onUnknownRoute]. If [home], [routes], /// to [Navigator.onGenerateRoute] and [Navigator.onUnknownRoute]. If [home], [routes],
/// and [builder] are null, or if they fail to create a requested route, /// and [builder] are null, or if they fail to create a requested route,
...@@ -643,19 +641,17 @@ class _WidgetsAppState extends State<WidgetsApp> implements WidgetsBindingObserv ...@@ -643,19 +641,17 @@ class _WidgetsAppState extends State<WidgetsApp> implements WidgetsBindingObserv
Route<dynamic> _onGenerateRoute(RouteSettings settings) { Route<dynamic> _onGenerateRoute(RouteSettings settings) {
final String name = settings.name; final String name = settings.name;
WidgetBuilder builder; final WidgetBuilder pageContentBuilder = name == Navigator.defaultRouteName && widget.home != null
if (name == Navigator.defaultRouteName && widget.home != null) { ? (BuildContext context) => widget.home
builder = (BuildContext context) => widget.home; : widget.routes[name];
} else {
builder = widget.routes[name]; if (pageContentBuilder != null) {
}
if (builder != null) {
assert(widget.pageRouteBuilder != null, assert(widget.pageRouteBuilder != null,
'The default onGenerateRoute handler for WidgetsApp must have a ' 'The default onGenerateRoute handler for WidgetsApp must have a '
'pageRouteBuilder set if the home or routes properties are set.'); 'pageRouteBuilder set if the home or routes properties are set.');
final Route<dynamic> route = widget.pageRouteBuilder( final Route<dynamic> route = widget.pageRouteBuilder(
settings, settings,
builder, pageContentBuilder,
); );
assert(route != null, assert(route != null,
'The pageRouteBuilder for WidgetsApp must return a valid non-null Route.'); 'The pageRouteBuilder for WidgetsApp must return a valid non-null Route.');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment