From e52bda2cd0e42ef12f92a4a3a8610cce448b8d72 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 20 Jan 2017 15:39:06 -0800 Subject: [PATCH] Document the value that Navigator.push completes to (#7569) Also, synchronize the docs between Navigator.push and NavigatorState.push (and friends). --- .../flutter/lib/src/widgets/navigator.dart | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/packages/flutter/lib/src/widgets/navigator.dart b/packages/flutter/lib/src/widgets/navigator.dart index 71c529b1552..591f48070d5 100644 --- a/packages/flutter/lib/src/widgets/navigator.dart +++ b/packages/flutter/lib/src/widgets/navigator.dart @@ -460,7 +460,8 @@ class Navigator extends StatefulWidget { /// The route name will be passed to that navigator's [onGenerateRoute] /// callback. The returned route will be pushed into the navigator. /// - /// Returns a Future that completes when the pushed route is popped. + /// Returns a [Future] that completes to the `result` value passed to [pop] + /// when the pushed route is popped off the navigator. /// /// Typical usage is as follows: /// @@ -471,14 +472,19 @@ class Navigator extends StatefulWidget { return Navigator.of(context).pushNamed(routeName); } - /// Push a route onto the navigator that most tightly encloses the given context. + /// Adds the given route to the history of the navigator that most tightly + /// encloses the given context, and transitions to it. /// - /// Adds the given route to the Navigator's history, and transitions to it. - /// The route will have didPush() and didChangeNext() called on it; the - /// previous route, if any, will have didChangeNext() called on it; and the - /// Navigator observer, if any, will have didPush() called on it. + /// The new route and the previous route (if any) are notified (see + /// [Route.didPush] and [Route.didChangeNext]). If the [Navigator] has an + /// [Navigator.observer], it will be notified as well (see + /// [NavigatorObserver.didPush]). /// - /// Returns a Future that completes when the pushed route is popped. + /// Ongoing gestures within the current route are canceled when a new route is + /// pushed. + /// + /// Returns a [Future] that completes to the `result` value passed to [pop] + /// when the pushed route is popped off the navigator. static Future push(BuildContext context, Route route) { return Navigator.of(context).push(route); } @@ -559,7 +565,8 @@ class Navigator extends StatefulWidget { /// route. The type of `result`, if provided, must match the type argument of /// the class of the current route. (In practice, this is usually "dynamic".) /// - /// Returns a Future that completes when the pushed route is popped. + /// Returns a [Future] that completes to the `result` value passed to [pop] + /// when the pushed route is popped off the navigator. /// /// Typical usage is as follows: /// @@ -653,10 +660,19 @@ class NavigatorState extends State with TickerProviderStateMixin { bool _debugLocked = false; // used to prevent re-entrant calls to push, pop, and friends - /// Looks up the route with the given name using [Navigator.onGenerateRoute], - /// and then [push]es that route. + /// Push a named route onto the navigator. /// - /// Returns a Future that completes when the pushed route is popped. + /// The route name will be passed to [Navigator.onGenerateRoute]. The returned + /// route will be pushed into the navigator. + /// + /// Returns a [Future] that completes to the `result` value passed to [pop] + /// when the pushed route is popped off the navigator. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// Navigator.of(context).pushNamed('/nyc/1776'); + /// ``` Future pushNamed(String name) { assert(!_debugLocked); assert(name != null); @@ -680,7 +696,8 @@ class NavigatorState extends State with TickerProviderStateMixin { /// Ongoing gestures within the current route are canceled when a new route is /// pushed. /// - /// Returns a Future that completes when the pushed route is popped. + /// Returns a [Future] that completes to the `result` value passed to [pop] + /// when the pushed route is popped off the navigator. Future push(Route route) { assert(!_debugLocked); assert(() { _debugLocked = true; return true; });