Unverified Commit 7f41ab25 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Fix (insert|move|remove)RenderObjectChild methods in base class (#123276)

parent 31798757
......@@ -856,7 +856,7 @@ class _CupertinoDialogRenderElement extends RenderObjectElement {
@override
void moveRenderObjectChild(RenderObject child, _AlertDialogSections oldSlot, _AlertDialogSections newSlot) {
if (!allowMoveRenderObjectChild) {
super.moveRenderObjectChild(child, oldSlot, newSlot);
assert(false);
return;
}
......
......@@ -6290,30 +6290,7 @@ abstract class RenderObjectElement extends Element {
/// [IndexedSlot] is a convenient value for the slot.
/// {@endtemplate}
@protected
void insertRenderObjectChild(covariant RenderObject child, covariant Object? slot) {
assert(() {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('RenderObjectElement.insertChildRenderObject() is deprecated.'),
toDiagnosticsNode(
name: 'insertChildRenderObject() was called on this Element',
style: DiagnosticsTreeStyle.shallow,
),
ErrorDescription(
'insertChildRenderObject() has been deprecated in favor of '
'insertRenderObjectChild(). See https://github.com/flutter/flutter/issues/63269 '
'for details.',
),
ErrorHint(
'Rather than overriding insertChildRenderObject() in your '
'RenderObjectElement subclass, override insertRenderObjectChild() instead, '
"and DON'T call super.insertRenderObjectChild(). If you're implementing a "
'new RenderObjectElement, you should override/implement '
'insertRenderObjectChild(), moveRenderObjectChild(), and '
'removeRenderObjectChild().',
),
]);
}());
}
void insertRenderObjectChild(covariant RenderObject child, covariant Object? slot);
/// Move the given child from the given old slot to the given new slot.
///
......@@ -6330,60 +6307,14 @@ 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 Object? oldSlot, covariant Object? newSlot) {
assert(() {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('RenderObjectElement.moveChildRenderObject() is deprecated.'),
toDiagnosticsNode(
name: 'super.moveChildRenderObject() was called on this Element',
style: DiagnosticsTreeStyle.shallow,
),
ErrorDescription(
'moveChildRenderObject() has been deprecated in favor of '
'moveRenderObjectChild(). See https://github.com/flutter/flutter/issues/63269 '
'for details.',
),
ErrorHint(
'Rather than overriding moveChildRenderObject() in your '
'RenderObjectElement subclass, override moveRenderObjectChild() instead, '
"and DON'T call super.moveRenderObjectChild(). If you're implementing a "
'new RenderObjectElement, you should override/implement '
'insertRenderObjectChild(), moveRenderObjectChild(), and '
'removeRenderObjectChild().',
),
]);
}());
}
void moveRenderObjectChild(covariant RenderObject child, covariant Object? oldSlot, covariant Object? newSlot);
/// Remove the given child from [renderObject].
///
/// 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 Object? slot) {
assert(() {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('RenderObjectElement.removeChildRenderObject() is deprecated.'),
toDiagnosticsNode(
name: 'super.removeChildRenderObject() was called on this Element',
style: DiagnosticsTreeStyle.shallow,
),
ErrorDescription(
'removeChildRenderObject() has been deprecated in favor of '
'removeRenderObjectChild(). See https://github.com/flutter/flutter/issues/63269 '
'for details.',
),
ErrorHint(
'Rather than overriding removeChildRenderObject() in your '
'RenderObjectElement subclass, override removeRenderObjectChild() instead, '
"and DON'T call super.removeRenderObjectChild(). If you're implementing a "
'new RenderObjectElement, you should override/implement '
'insertRenderObjectChild(), moveRenderObjectChild(), and '
'removeRenderObjectChild().',
),
]);
}());
}
void removeRenderObjectChild(covariant RenderObject child, covariant Object? slot);
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
......
......@@ -2119,6 +2119,15 @@ class FakeLeafRenderObject extends RenderBox {
class TestRenderObjectElement extends RenderObjectElement {
TestRenderObjectElement() : super(Table());
@override
void insertRenderObjectChild(covariant RenderObject child, covariant Object? slot) { }
@override
void moveRenderObjectChild(covariant RenderObject child, covariant Object? oldSlot, covariant Object? newSlot) { }
@override
void removeRenderObjectChild(covariant RenderObject child, covariant Object? slot) { }
}
class _EmptyWidget extends Widget {
......
......@@ -66,6 +66,15 @@ class _TestElement extends RootRenderObjectElement{
mount(null, null);
deactivate();
}
@override
void insertRenderObjectChild(covariant RenderObject child, covariant Object? slot) { }
@override
void moveRenderObjectChild(covariant RenderObject child, covariant Object? oldSlot, covariant Object? newSlot) { }
@override
void removeRenderObjectChild(covariant RenderObject child, covariant Object? slot) { }
}
class _TestRenderObject extends RenderObject {
......
......@@ -105,6 +105,15 @@ abstract class SwapperElement extends RenderObjectElement {
swapper = updateChild(swapper, widget.swapper, swapperIsOnTop);
swapperIsOnTop = !swapperIsOnTop;
}
@override
void insertRenderObjectChild(covariant RenderObject child, covariant Object? slot) { }
@override
void moveRenderObjectChild(covariant RenderObject child, covariant Object? oldSlot, covariant Object? newSlot) { }
@override
void removeRenderObjectChild(covariant RenderObject child, covariant Object? slot) { }
}
class SwapperElementWithProperOverrides extends SwapperElement {
......@@ -288,26 +297,4 @@ void main() {
expect(swapper.removeSlots, contains('stable'));
expect(swapper.removeSlots, contains(false));
});
testWidgets('RenderObjectElement *ChildRenderObject methods fail with deprecation message', (WidgetTester tester) async {
const Key redKey = ValueKey<String>('red');
const Key blueKey = ValueKey<String>('blue');
Widget widget() {
return SwapperWithNoOverrides(
stable: ColoredBox(
key: redKey,
color: Color(nonconst(0xffff0000)),
),
swapper: ColoredBox(
key: blueKey,
color: Color(nonconst(0xff0000ff)),
),
);
}
await tester.pumpWidget(widget());
final FlutterError error = tester.takeException() as FlutterError;
final ErrorSummary summary = error.diagnostics.first as ErrorSummary;
expect(summary.toString(), contains('deprecated'));
});
}
......@@ -63,6 +63,15 @@ class _TestElement extends RootRenderObjectElement{
mount(null, null);
deactivate();
}
@override
void insertRenderObjectChild(covariant RenderObject child, covariant Object? slot) { }
@override
void moveRenderObjectChild(covariant RenderObject child, covariant Object? oldSlot, covariant Object? newSlot) { }
@override
void removeRenderObjectChild(covariant RenderObject child, covariant Object? slot) { }
}
class _MyStatefulWidget extends StatefulWidget {
......
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