diff --git a/packages/flutter/lib/src/cupertino/text_selection_toolbar.dart b/packages/flutter/lib/src/cupertino/text_selection_toolbar.dart index e3380a25fb..ad39ccd62f 100644 --- a/packages/flutter/lib/src/cupertino/text_selection_toolbar.dart +++ b/packages/flutter/lib/src/cupertino/text_selection_toolbar.dart @@ -594,7 +594,7 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement { assert(!_forgottenChildren.contains(child)); // Handle forgetting a child in children or in a slot. if (slotToChild.containsKey(child.slot)) { - final _CupertinoTextSelectionToolbarItemsSlot slot = child.slot as _CupertinoTextSelectionToolbarItemsSlot; + final _CupertinoTextSelectionToolbarItemsSlot slot = child.slot! as _CupertinoTextSelectionToolbarItemsSlot; slotToChild.remove(slot); } else { _forgottenChildren.add(child); diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 9254944db0..f5af4582b7 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -1086,7 +1086,7 @@ abstract class State with Diagnosticable { } return true; }()); - final dynamic result = fn() as dynamic; + final Object? result = fn() as dynamic; assert(() { if (result is Future) { throw FlutterError.fromParts([ @@ -3038,10 +3038,11 @@ abstract class Element extends DiagnosticableTree implements BuildContext { /// Information set by parent to define where this child fits in its parent's /// child list. /// - /// Subclasses of Element that only have one child should use null for - /// the slot for that child. - dynamic get slot => _slot; - dynamic _slot; + /// A child widget's slot is determined when the parent's [updateChild] method + /// is called to inflate the child widget. See [RenderObjectElement] for more + /// details on slots. + Object? get slot => _slot; + Object? _slot; /// An integer that is guaranteed to be greater than the parent's, if any. /// The element at the root of the tree must have a depth greater than 0. @@ -3304,7 +3305,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext { /// /// See the [RenderObjectElement] documentation for more information on slots. @protected - Element? updateChild(Element? child, Widget? newWidget, dynamic newSlot) { + Element? updateChild(Element? child, Widget? newWidget, Object? newSlot) { if (newWidget == null) { if (child != null) deactivateChild(child); @@ -3389,7 +3390,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext { /// Implementations of this method should start with a call to the inherited /// method, as in `super.mount(parent, newSlot)`. @mustCallSuper - void mount(Element? parent, dynamic newSlot) { + void mount(Element? parent, Object? newSlot) { assert(_lifecycleState == _ElementLifecycle.initial); assert(widget != null); assert(_parent == null); @@ -3454,7 +3455,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext { /// subclasses that have multiple children, when child moves from one position /// to another in this element's child list. @protected - void updateSlotForChild(Element child, dynamic newSlot) { + void updateSlotForChild(Element child, Object? newSlot) { assert(_lifecycleState == _ElementLifecycle.active); assert(child != null); assert(child._parent == this); @@ -3466,7 +3467,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext { visit(child); } - void _updateSlot(dynamic newSlot) { + void _updateSlot(Object? newSlot) { assert(_lifecycleState == _ElementLifecycle.active); assert(widget != null); assert(_parent != null); @@ -3508,7 +3509,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext { /// adding [renderObject] to the render tree. /// /// The `newSlot` argument specifies the new value for this element's [slot]. - void attachRenderObject(dynamic newSlot) { + void attachRenderObject(Object? newSlot) { assert(_slot == null); visitChildren((Element child) { child.attachRenderObject(newSlot); @@ -3577,7 +3578,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext { /// The element returned by this function will already have been mounted and /// will be in the "active" lifecycle state. @protected - Element inflateWidget(Widget newWidget, dynamic newSlot) { + Element inflateWidget(Widget newWidget, Object? newSlot) { assert(newWidget != null); final Key? key = newWidget.key; if (key is GlobalKey) { @@ -3678,7 +3679,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext { }()); } - void _activateWithParent(Element parent, dynamic newSlot) { + void _activateWithParent(Element parent, Object? newSlot) { assert(_lifecycleState == _ElementLifecycle.inactive); _parent = parent; assert(() { @@ -4421,7 +4422,7 @@ class ErrorWidget extends LeafRenderObjectWidget { return ErrorWidget.withDetails(message: message, error: exception is FlutterError ? exception : null); } - static String _stringify(dynamic exception) { + static String _stringify(Object? exception) { try { return exception.toString(); } catch (e) { @@ -4533,7 +4534,7 @@ abstract class ComponentElement extends Element { bool get debugDoingBuild => _debugDoingBuild; @override - void mount(Element? parent, dynamic newSlot) { + void mount(Element? parent, Object? newSlot) { super.mount(parent, newSlot); assert(_child == null); assert(_lifecycleState == _ElementLifecycle.active); @@ -4700,7 +4701,7 @@ class StatefulElement extends ComponentElement { assert(state._debugLifecycleState == _StateLifecycle.created); try { _debugSetAllowIgnoredCallsToMarkNeedsBuild(true); - final dynamic debugCheckForReturnedFuture = state.initState() as dynamic; + final Object? debugCheckForReturnedFuture = state.initState() as dynamic; assert(() { if (debugCheckForReturnedFuture is Future) { throw FlutterError.fromParts([ @@ -4750,7 +4751,7 @@ class StatefulElement extends ComponentElement { state._widget = widget as StatefulWidget; try { _debugSetAllowIgnoredCallsToMarkNeedsBuild(true); - final dynamic debugCheckForReturnedFuture = state.didUpdateWidget(oldWidget) as dynamic; + final Object? debugCheckForReturnedFuture = state.didUpdateWidget(oldWidget) as dynamic; assert(() { if (debugCheckForReturnedFuture is Future) { throw FlutterError.fromParts([ @@ -5237,13 +5238,17 @@ class InheritedElement extends ProxyElement { /// corresponds to whatever [RenderObject] its child (the element returned by /// its [StatelessWidget.build] method) corresponds to. /// -/// Each child is therefore assigned a _slot_ token. This is an identifier whose +/// Each child is therefore assigned a _[slot]_ token. This is an identifier whose /// meaning is private to this [RenderObjectElement] node. When the descendant /// that finally produces the [RenderObject] is ready to attach it to this /// node's render object, it passes that slot token back to this node, and that /// allows this node to cheaply identify where to put the child render object /// relative to the others in the parent render object. /// +/// A child's [slot] is determined when the parent calls [updateChild] to +/// inflate the child (see the next section). It can be updated by calling +/// [updateSlotForChild]. +/// /// ### Updating children /// /// Early in the lifecycle of an element, the framework calls the [mount] @@ -5409,7 +5414,7 @@ abstract class RenderObjectElement extends Element { } @override - void mount(Element? parent, dynamic newSlot) { + void mount(Element? parent, Object? newSlot) { super.mount(parent, newSlot); assert(() { _debugDoingBuild = true; @@ -5716,8 +5721,8 @@ abstract class RenderObjectElement extends Element { } @override - void _updateSlot(dynamic newSlot) { - final dynamic oldSlot = slot; + void _updateSlot(Object? newSlot) { + final Object? oldSlot = slot; assert(oldSlot != newSlot); super._updateSlot(newSlot); assert(slot == newSlot); @@ -5725,7 +5730,7 @@ abstract class RenderObjectElement extends Element { } @override - void attachRenderObject(dynamic newSlot) { + void attachRenderObject(Object? newSlot) { assert(_ancestorRenderObjectElement == null); _slot = newSlot; _ancestorRenderObjectElement = _findAncestorRenderObjectElement(); @@ -5770,7 +5775,7 @@ abstract class RenderObjectElement extends Element { 'Override insertRenderObjectChild instead. ' 'This feature was deprecated after v1.21.0-9.0.pre.' ) - void insertChildRenderObject(covariant RenderObject child, covariant dynamic slot) { + void insertChildRenderObject(covariant RenderObject child, covariant Object? slot) { assert(() { throw FlutterError.fromParts([ ErrorSummary('RenderObjectElement.insertChildRenderObject() is deprecated.'), @@ -5800,7 +5805,7 @@ abstract class RenderObjectElement extends Element { /// [IndexedSlot] is a convenient value for the slot. /// {@endtemplate} @protected - void insertRenderObjectChild(covariant RenderObject child, covariant dynamic slot) { + void insertRenderObjectChild(covariant RenderObject child, covariant Object? slot) { insertChildRenderObject(child, slot); } @@ -5843,7 +5848,7 @@ abstract class RenderObjectElement extends Element { 'Override moveRenderObjectChild instead. ' 'This feature was deprecated after v1.21.0-9.0.pre.' ) - void moveChildRenderObject(covariant RenderObject child, covariant dynamic slot) { + void moveChildRenderObject(covariant RenderObject child, covariant Object? slot) { assert(() { throw FlutterError.fromParts([ ErrorSummary('RenderObjectElement.moveChildRenderObject() is deprecated.'), @@ -5879,7 +5884,7 @@ abstract class RenderObjectElement extends Element { /// compared against each other for the purposes of updating one slot with the /// element from another slot) would never call this. @protected - void moveRenderObjectChild(covariant RenderObject child, covariant dynamic oldSlot, covariant dynamic newSlot) { + void moveRenderObjectChild(covariant RenderObject child, covariant Object? oldSlot, covariant Object? newSlot) { moveChildRenderObject(child, newSlot); } @@ -5936,7 +5941,7 @@ abstract class RenderObjectElement extends Element { /// The given child is guaranteed to have been inserted at the given `slot` /// and have [renderObject] as its parent. @protected - void removeRenderObjectChild(covariant RenderObject child, covariant dynamic slot) { + void removeRenderObjectChild(covariant RenderObject child, covariant Object? slot) { removeChildRenderObject(child); } @@ -5970,7 +5975,7 @@ abstract class RootRenderObjectElement extends RenderObjectElement { } @override - void mount(Element? parent, dynamic newSlot) { + void mount(Element? parent, Object? newSlot) { // Root elements should never have parents. assert(parent == null); assert(newSlot == null); @@ -5990,17 +5995,17 @@ class LeafRenderObjectElement extends RenderObjectElement { } @override - void insertRenderObjectChild(RenderObject child, dynamic slot) { + void insertRenderObjectChild(RenderObject child, Object? slot) { assert(false); } @override - void moveRenderObjectChild(RenderObject child, dynamic oldSlot, dynamic newSlot) { + void moveRenderObjectChild(RenderObject child, Object? oldSlot, Object? newSlot) { assert(false); } @override - void removeRenderObjectChild(RenderObject child, dynamic slot) { + void removeRenderObjectChild(RenderObject child, Object? slot) { assert(false); } @@ -6040,7 +6045,7 @@ class SingleChildRenderObjectElement extends RenderObjectElement { } @override - void mount(Element? parent, dynamic newSlot) { + void mount(Element? parent, Object? newSlot) { super.mount(parent, newSlot); _child = updateChild(_child, widget.child, null); } @@ -6053,7 +6058,7 @@ class SingleChildRenderObjectElement extends RenderObjectElement { } @override - void insertRenderObjectChild(RenderObject child, dynamic slot) { + void insertRenderObjectChild(RenderObject child, Object? slot) { final RenderObjectWithChildMixin renderObject = this.renderObject as RenderObjectWithChildMixin; assert(slot == null); assert(renderObject.debugValidateChild(child)); @@ -6062,12 +6067,12 @@ class SingleChildRenderObjectElement extends RenderObjectElement { } @override - void moveRenderObjectChild(RenderObject child, dynamic oldSlot, dynamic newSlot) { + void moveRenderObjectChild(RenderObject child, Object? oldSlot, Object? newSlot) { assert(false); } @override - void removeRenderObjectChild(RenderObject child, dynamic slot) { + void removeRenderObjectChild(RenderObject child, Object? slot) { final RenderObjectWithChildMixin renderObject = this.renderObject as RenderObjectWithChildMixin; assert(slot == null); assert(renderObject.child == child); @@ -6133,7 +6138,7 @@ class MultiChildRenderObjectElement extends RenderObjectElement { } @override - void removeRenderObjectChild(RenderObject child, dynamic slot) { + void removeRenderObjectChild(RenderObject child, Object? slot) { final ContainerRenderObjectMixin> renderObject = this.renderObject; assert(child.parent == renderObject); renderObject.remove(child); @@ -6157,7 +6162,7 @@ class MultiChildRenderObjectElement extends RenderObjectElement { } @override - void mount(Element? parent, dynamic newSlot) { + void mount(Element? parent, Object? newSlot) { super.mount(parent, newSlot); final List children = List.filled(widget.children.length, _NullElement.instance, growable: false); Element? previousChild;