Unverified Commit 01201b5f authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Add documentation talking about ScrollPhysics.applyTo(null) (#67585)

parent 99016e3f
...@@ -85,21 +85,28 @@ class ScrollPhysics { ...@@ -85,21 +85,28 @@ class ScrollPhysics {
@protected @protected
ScrollPhysics? buildParent(ScrollPhysics? ancestor) => parent?.applyTo(ancestor) ?? ancestor; ScrollPhysics? buildParent(ScrollPhysics? ancestor) => parent?.applyTo(ancestor) ?? ancestor;
/// If [parent] is null then return a [ScrollPhysics] with the same /// Combines this [ScrollPhysics] instance with the given physics.
/// [runtimeType] where the [parent] has been replaced with the [ancestor].
/// ///
/// If this scroll physics object already has a parent, then this method /// The returned object uses this instance's physics when it has an
/// is applied recursively and ancestor will appear at the end of the /// opinion, and defers to the given `ancestor` object's physics
/// existing chain of parents. /// when it does not.
/// ///
/// The returned object will combine some of the behaviors from this /// If [parent] is null then this returns a [ScrollPhysics] with the
/// [ScrollPhysics] instance and some of the behaviors from [ancestor]. /// same [runtimeType], but where the [parent] has been replaced
/// with the [ancestor].
///
/// If this scroll physics object already has a parent, then this
/// method is applied recursively and ancestor will appear at the
/// end of the existing chain of parents.
///
/// Calling this method with a null argument will copy the current
/// object. This is inefficient.
/// ///
/// {@tool snippet} /// {@tool snippet}
/// ///
/// In the following example, the [applyTo] method is used to combine the /// In the following example, the [applyTo] method is used to combine the
/// scroll physics of two [ScrollPhysics] objects, the resulting [ScrollPhysics] /// scroll physics of two [ScrollPhysics] objects. The resulting [ScrollPhysics]
/// `x` has the same behavior as `y`: /// `x` has the same behavior as `y`.
/// ///
/// ```dart /// ```dart
/// final FooScrollPhysics x = FooScrollPhysics().applyTo(BarScrollPhysics()); /// final FooScrollPhysics x = FooScrollPhysics().applyTo(BarScrollPhysics());
...@@ -107,10 +114,27 @@ class ScrollPhysics { ...@@ -107,10 +114,27 @@ class ScrollPhysics {
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
/// ///
/// ## Implementing `applyTo`
///
/// When creating a custom [ScrollPhysics] subclass, this method
/// must be implemented. If the physics class has no constructor
/// arguments, then implementing this method is merely a matter of
/// calling the constructor with a [parent] constructed using
/// [buildParent], as follows:
///
/// ```dart
/// FooScrollPhysics applyTo(ScrollPhysics ancestor) {
/// return FooScrollPhysics(parent: buildParent(ancestor));
/// }
/// ```
///
/// If the physics class has constructor arguments, they must be passed to
/// the constructor here as well, so as to create a clone.
///
/// See also: /// See also:
/// ///
/// * [buildParent], a utility method that's often used to define [applyTo] /// * [buildParent], a utility method that's often used to define [applyTo]
/// methods for ScrollPhysics subclasses. /// methods for [ScrollPhysics] subclasses.
ScrollPhysics applyTo(ScrollPhysics? ancestor) { ScrollPhysics applyTo(ScrollPhysics? ancestor) {
return ScrollPhysics(parent: buildParent(ancestor)); return ScrollPhysics(parent: buildParent(ancestor));
} }
......
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