From f00391196795624cb8966478ecbde9eeeb2b9450 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Wed, 19 Jul 2023 09:36:08 -0700 Subject: [PATCH] Fix contradictory advice in "detach" docs; cut redundancy in "attach" (#130688) Fixes #115525. On [AbstractNode.detach] and its two progeny [RenderNode.detach] and [Layer.detach], the docs said both to call the inherited method before detaching children, and to end by doing so. The former advice is what's enforced by an assertion in the base implementation, so cut out the other. The corresponding [attach] methods redundantly said twice to call the inherited method first, so cut the redundancy. Leave in place the version more recently added (in #76021), because that PR shows the old version must have been easy to overlook. --- packages/flutter/lib/src/foundation/node.dart | 17 ++++++----------- packages/flutter/lib/src/rendering/layer.dart | 17 ++++++----------- packages/flutter/lib/src/rendering/object.dart | 17 ++++++----------- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/packages/flutter/lib/src/foundation/node.dart b/packages/flutter/lib/src/foundation/node.dart index ca383fb152..a32f30a481 100644 --- a/packages/flutter/lib/src/foundation/node.dart +++ b/packages/flutter/lib/src/foundation/node.dart @@ -92,12 +92,9 @@ class AbstractNode { /// Typically called only from the [parent]'s [attach] method, and by the /// [owner] to mark the root of a tree as attached. /// - /// Subclasses with children should override this method to first call their - /// inherited [attach] method, and then [attach] all their children to the - /// same [owner]. - /// - /// Implementations of this method should start with a call to the inherited - /// method, as in `super.attach(owner)`. + /// Subclasses with children should override this method to + /// [attach] all their children to the same [owner] + /// after calling the inherited method, as in `super.attach(owner)`. @mustCallSuper void attach(covariant Object owner) { assert(_owner == null); @@ -109,11 +106,9 @@ class AbstractNode { /// Typically called only from the [parent]'s [detach], and by the [owner] to /// mark the root of a tree as detached. /// - /// Subclasses with children should override this method to first call their - /// inherited [detach] method, and then [detach] all their children. - /// - /// Implementations of this method should end with a call to the inherited - /// method, as in `super.detach()`. + /// Subclasses with children should override this method to + /// [detach] all their children after calling the inherited method, + /// as in `super.detach()`. @mustCallSuper void detach() { assert(_owner != null); diff --git a/packages/flutter/lib/src/rendering/layer.dart b/packages/flutter/lib/src/rendering/layer.dart index 1cff262dde..d777791863 100644 --- a/packages/flutter/lib/src/rendering/layer.dart +++ b/packages/flutter/lib/src/rendering/layer.dart @@ -518,12 +518,9 @@ abstract class Layer with DiagnosticableTreeMixin { /// Typically called only from the [parent]'s [attach] method, and by the /// [owner] to mark the root of a tree as attached. /// - /// Subclasses with children should override this method to first call their - /// inherited [attach] method, and then [attach] all their children to the - /// same [owner]. - /// - /// Implementations of this method should start with a call to the inherited - /// method, as in `super.attach(owner)`. + /// Subclasses with children should override this method to + /// [attach] all their children to the same [owner] + /// after calling the inherited method, as in `super.attach(owner)`. @mustCallSuper void attach(covariant Object owner) { assert(_owner == null); @@ -535,11 +532,9 @@ abstract class Layer with DiagnosticableTreeMixin { /// Typically called only from the [parent]'s [detach], and by the [owner] to /// mark the root of a tree as detached. /// - /// Subclasses with children should override this method to first call their - /// inherited [detach] method, and then [detach] all their children. - /// - /// Implementations of this method should end with a call to the inherited - /// method, as in `super.detach()`. + /// Subclasses with children should override this method to + /// [detach] all their children after calling the inherited method, + /// as in `super.detach()`. @mustCallSuper void detach() { assert(_owner != null); diff --git a/packages/flutter/lib/src/rendering/object.dart b/packages/flutter/lib/src/rendering/object.dart index 730bf50506..d988fc923e 100644 --- a/packages/flutter/lib/src/rendering/object.dart +++ b/packages/flutter/lib/src/rendering/object.dart @@ -2074,12 +2074,9 @@ abstract class RenderObject with DiagnosticableTreeMixin implements HitTestTarge /// Typically called only from the [parent]'s [attach] method, and by the /// [owner] to mark the root of a tree as attached. /// - /// Subclasses with children should override this method to first call their - /// inherited [attach] method, and then [attach] all their children to the - /// same [owner]. - /// - /// Implementations of this method should start with a call to the inherited - /// method, as in `super.attach(owner)`. + /// Subclasses with children should override this method to + /// [attach] all their children to the same [owner] + /// after calling the inherited method, as in `super.attach(owner)`. @mustCallSuper void attach(PipelineOwner owner) { assert(!_debugDisposed); @@ -2116,11 +2113,9 @@ abstract class RenderObject with DiagnosticableTreeMixin implements HitTestTarge /// Typically called only from the [parent]'s [detach], and by the [owner] to /// mark the root of a tree as detached. /// - /// Subclasses with children should override this method to first call their - /// inherited [detach] method, and then [detach] all their children. - /// - /// Implementations of this method should end with a call to the inherited - /// method, as in `super.detach()`. + /// Subclasses with children should override this method to + /// [detach] all their children after calling the inherited method, + /// as in `super.detach()`. @mustCallSuper void detach() { assert(_owner != null);