Unverified Commit e5322acc authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Change some dynamics to Object? and document slot better (#77026)

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