Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
ce40de69
Unverified
Commit
ce40de69
authored
Aug 20, 2020
by
Mehmet Fidanboylu
Committed by
GitHub
Aug 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "(insert|move|remove)ChildRenderObject Deprecation: Step 1 (#64189)" (#64249)
This reverts commit
21cfed34
.
parent
d9188c19
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
85 additions
and
629 deletions
+85
-629
action_sheet.dart
packages/flutter/lib/src/cupertino/action_sheet.dart
+4
-4
dialog.dart
packages/flutter/lib/src/cupertino/dialog.dart
+3
-3
text_selection.dart
packages/flutter/lib/src/cupertino/text_selection.dart
+7
-8
chip.dart
packages/flutter/lib/src/material/chip.dart
+7
-6
input_decorator.dart
packages/flutter/lib/src/material/input_decorator.dart
+7
-6
list_tile.dart
packages/flutter/lib/src/material/list_tile.dart
+7
-6
binding.dart
packages/flutter/lib/src/widgets/binding.dart
+3
-3
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+23
-186
layout_builder.dart
packages/flutter/lib/src/widgets/layout_builder.dart
+3
-3
list_wheel_scroll_view.dart
packages/flutter/lib/src/widgets/list_wheel_scroll_view.dart
+3
-3
sliver.dart
packages/flutter/lib/src/widgets/sliver.dart
+5
-5
sliver_persistent_header.dart
...ges/flutter/lib/src/widgets/sliver_persistent_header.dart
+3
-3
sliver_prototype_extent_list.dart
...flutter/lib/src/widgets/sliver_prototype_extent_list.dart
+7
-7
table.dart
packages/flutter/lib/src/widgets/table.dart
+3
-3
render_object_element_test.dart
...ages/flutter/test/widgets/render_object_element_test.dart
+0
-383
No files found.
packages/flutter/lib/src/cupertino/action_sheet.dart
View file @
ce40de69
...
...
@@ -448,13 +448,13 @@ class _CupertinoAlertRenderElement extends RenderObjectElement {
}
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
_AlertSections
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
_AlertSections
slot
)
{
_placeChildInSlot
(
child
,
slot
);
}
@override
void
move
RenderObjectChild
(
RenderObject
child
,
_AlertSections
oldSlot
,
_AlertSections
newS
lot
)
{
_placeChildInSlot
(
child
,
newS
lot
);
void
move
ChildRenderObject
(
RenderObject
child
,
_AlertSections
s
lot
)
{
_placeChildInSlot
(
child
,
s
lot
);
}
@override
...
...
@@ -478,7 +478,7 @@ class _CupertinoAlertRenderElement extends RenderObjectElement {
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
_AlertSections
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
assert
(
child
==
renderObject
.
contentSection
||
child
==
renderObject
.
actionsSection
);
if
(
renderObject
.
contentSection
==
child
)
{
renderObject
.
contentSection
=
null
;
...
...
packages/flutter/lib/src/cupertino/dialog.dart
View file @
ce40de69
...
...
@@ -433,7 +433,7 @@ class _CupertinoDialogRenderElement extends RenderObjectElement {
}
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
_AlertDialogSections
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
_AlertDialogSections
slot
)
{
assert
(
slot
!=
null
);
switch
(
slot
)
{
case
_AlertDialogSections
.
contentSection
:
...
...
@@ -446,7 +446,7 @@ class _CupertinoDialogRenderElement extends RenderObjectElement {
}
@override
void
move
RenderObjectChild
(
RenderObject
child
,
_AlertDialogSections
oldSlot
,
_AlertDialogSections
newS
lot
)
{
void
move
ChildRenderObject
(
RenderObject
child
,
_AlertDialogSections
s
lot
)
{
assert
(
false
);
}
...
...
@@ -470,7 +470,7 @@ class _CupertinoDialogRenderElement extends RenderObjectElement {
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
_AlertDialogSections
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
assert
(
child
==
renderObject
.
contentSection
||
child
==
renderObject
.
actionsSection
);
if
(
renderObject
.
contentSection
==
child
)
{
renderObject
.
contentSection
=
null
;
...
...
packages/flutter/lib/src/cupertino/text_selection.dart
View file @
ce40de69
...
...
@@ -775,9 +775,10 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
}
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
dynamic
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
dynamic
slot
)
{
if
(
slot
is
_CupertinoTextSelectionToolbarItemsSlot
)
{
assert
(
child
is
RenderBox
);
assert
(
slot
is
_CupertinoTextSelectionToolbarItemsSlot
);
_updateRenderObject
(
child
as
RenderBox
,
slot
);
assert
(
renderObject
.
childToSlot
.
containsKey
(
child
));
assert
(
renderObject
.
slotToChild
.
containsKey
(
slot
));
...
...
@@ -793,9 +794,9 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
// This is not reachable for children that don't have an IndexedSlot.
@override
void
move
RenderObjectChild
(
RenderObject
child
,
IndexedSlot
<
Element
>
oldSlot
,
IndexedSlot
<
Element
>
newS
lot
)
{
void
move
ChildRenderObject
(
RenderObject
child
,
IndexedSlot
<
Element
>
s
lot
)
{
assert
(
child
.
parent
==
renderObject
);
renderObject
.
move
(
child
as
RenderBox
,
after:
newS
lot
?.
value
?.
renderObject
as
RenderBox
);
renderObject
.
move
(
child
as
RenderBox
,
after:
s
lot
?.
value
?.
renderObject
as
RenderBox
);
}
static
bool
_shouldPaint
(
Element
child
)
{
...
...
@@ -803,20 +804,18 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
dynamic
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
// Check if the child is in a slot.
if
(
slot
is
_CupertinoTextSelectionToolbarItemsSlot
)
{
if
(
renderObject
.
childToSlot
.
containsKey
(
child
)
)
{
assert
(
child
is
RenderBox
);
assert
(
renderObject
.
slotToChild
.
containsKey
(
slot
));
assert
(
renderObject
.
childToSlot
.
containsKey
(
child
));
_updateRenderObject
(
null
,
slot
);
_updateRenderObject
(
null
,
renderObject
.
childToSlot
[
child
]
);
assert
(!
renderObject
.
childToSlot
.
containsKey
(
child
));
assert
(!
renderObject
.
slotToChild
.
containsKey
(
slot
));
return
;
}
// Otherwise look for it in the list of children.
assert
(
slot
is
IndexedSlot
);
assert
(
child
.
parent
==
renderObject
);
renderObject
.
remove
(
child
as
RenderBox
);
}
...
...
packages/flutter/lib/src/material/chip.dart
View file @
ce40de69
...
...
@@ -2148,25 +2148,26 @@ class _RenderChipElement extends RenderObjectElement {
}
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
_ChipSlot
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
dynamic
slotValue
)
{
assert
(
child
is
RenderBox
);
assert
(
slotValue
is
_ChipSlot
);
final
_ChipSlot
slot
=
slotValue
as
_ChipSlot
;
_updateRenderObject
(
child
,
slot
);
assert
(
renderObject
.
childToSlot
.
keys
.
contains
(
child
));
assert
(
renderObject
.
slotToChild
.
keys
.
contains
(
slot
));
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
_ChipSlot
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
assert
(
child
is
RenderBox
);
assert
(
renderObject
.
childToSlot
[
child
]
==
slot
);
assert
(
renderObject
.
slotToChild
[
slot
]
==
child
);
_updateRenderObject
(
null
,
slot
);
assert
(
renderObject
.
childToSlot
.
keys
.
contains
(
child
));
_updateRenderObject
(
null
,
renderObject
.
childToSlot
[
child
]);
assert
(!
renderObject
.
childToSlot
.
keys
.
contains
(
child
));
assert
(!
renderObject
.
slotToChild
.
keys
.
contains
(
slot
));
}
@override
void
move
RenderObjectChild
(
RenderObject
child
,
dynamic
oldSlot
,
dynamic
newSlot
)
{
void
move
ChildRenderObject
(
RenderObject
child
,
dynamic
slotValue
)
{
assert
(
false
,
'not reachable'
);
}
}
...
...
packages/flutter/lib/src/material/input_decorator.dart
View file @
ce40de69
...
...
@@ -1654,25 +1654,26 @@ class _RenderDecorationElement extends RenderObjectElement {
}
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
_DecorationSlot
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
dynamic
slotValue
)
{
assert
(
child
is
RenderBox
);
assert
(
slotValue
is
_DecorationSlot
);
final
_DecorationSlot
slot
=
slotValue
as
_DecorationSlot
;
_updateRenderObject
(
child
as
RenderBox
,
slot
);
assert
(
renderObject
.
childToSlot
.
keys
.
contains
(
child
));
assert
(
renderObject
.
slotToChild
.
keys
.
contains
(
slot
));
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
_DecorationSlot
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
assert
(
child
is
RenderBox
);
assert
(
renderObject
.
childToSlot
[
child
]
==
slot
);
assert
(
renderObject
.
slotToChild
[
slot
]
==
child
);
_updateRenderObject
(
null
,
slot
);
assert
(
renderObject
.
childToSlot
.
keys
.
contains
(
child
));
_updateRenderObject
(
null
,
renderObject
.
childToSlot
[
child
]);
assert
(!
renderObject
.
childToSlot
.
keys
.
contains
(
child
));
assert
(!
renderObject
.
slotToChild
.
keys
.
contains
(
slot
));
}
@override
void
move
RenderObjectChild
(
RenderObject
child
,
dynamic
oldSlot
,
dynamic
newSlot
)
{
void
move
ChildRenderObject
(
RenderObject
child
,
dynamic
slotValue
)
{
assert
(
false
,
'not reachable'
);
}
}
...
...
packages/flutter/lib/src/material/list_tile.dart
View file @
ce40de69
...
...
@@ -1250,25 +1250,26 @@ class _ListTileElement extends RenderObjectElement {
}
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
_ListTileSlot
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
dynamic
slotValue
)
{
assert
(
child
is
RenderBox
);
assert
(
slotValue
is
_ListTileSlot
);
final
_ListTileSlot
slot
=
slotValue
as
_ListTileSlot
;
_updateRenderObject
(
child
as
RenderBox
,
slot
);
assert
(
renderObject
.
childToSlot
.
keys
.
contains
(
child
));
assert
(
renderObject
.
slotToChild
.
keys
.
contains
(
slot
));
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
_ListTileSlot
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
assert
(
child
is
RenderBox
);
assert
(
renderObject
.
childToSlot
[
child
]
==
slot
);
assert
(
renderObject
.
slotToChild
[
slot
]
==
child
);
_updateRenderObject
(
null
,
slot
);
assert
(
renderObject
.
childToSlot
.
keys
.
contains
(
child
));
_updateRenderObject
(
null
,
renderObject
.
childToSlot
[
child
]);
assert
(!
renderObject
.
childToSlot
.
keys
.
contains
(
child
));
assert
(!
renderObject
.
slotToChild
.
keys
.
contains
(
slot
));
}
@override
void
move
RenderObjectChild
(
RenderObject
child
,
dynamic
oldSlot
,
dynamic
newSlot
)
{
void
move
ChildRenderObject
(
RenderObject
child
,
dynamic
slotValue
)
{
assert
(
false
,
'not reachable'
);
}
}
...
...
packages/flutter/lib/src/widgets/binding.dart
View file @
ce40de69
...
...
@@ -1268,19 +1268,19 @@ class RenderObjectToWidgetElement<T extends RenderObject> extends RootRenderObje
RenderObjectWithChildMixin
<
T
>
get
renderObject
=>
super
.
renderObject
as
RenderObjectWithChildMixin
<
T
>;
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
dynamic
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
dynamic
slot
)
{
assert
(
slot
==
_rootChildSlot
);
assert
(
renderObject
.
debugValidateChild
(
child
));
renderObject
.
child
=
child
as
T
;
}
@override
void
move
RenderObjectChild
(
RenderObject
child
,
dynamic
oldSlot
,
dynamic
newS
lot
)
{
void
move
ChildRenderObject
(
RenderObject
child
,
dynamic
s
lot
)
{
assert
(
false
);
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
dynamic
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
assert
(
renderObject
.
child
==
child
);
renderObject
.
child
=
null
;
}
...
...
packages/flutter/lib/src/widgets/framework.dart
View file @
ce40de69
...
...
@@ -3290,9 +3290,9 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
/// the "active" lifecycle state.
///
/// Subclasses that override this method are likely to want to also override
/// [update], [visitChildren], [RenderObjectElement.insert
RenderObjectChild
],
/// [RenderObjectElement.move
RenderObjectChild
], and
/// [RenderObjectElement.remove
RenderObjectChild
].
/// [update], [visitChildren], [RenderObjectElement.insert
ChildRenderObject
],
/// [RenderObjectElement.move
ChildRenderObject
], and
/// [RenderObjectElement.remove
ChildRenderObject
].
@mustCallSuper
void
mount
(
Element
parent
,
dynamic
newSlot
)
{
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
initial
);
...
...
@@ -5335,9 +5335,9 @@ class InheritedElement extends ProxyElement {
/// ### Maintaining the render object tree
///
/// Once a descendant produces a render object, it will call
/// [insert
RenderObjectChild
]. If the descendant's slot changes identity, it
/// will call [move
RenderObjectChild
]. If a descendant goes away, it will call
/// [remove
RenderObjectChild
].
/// [insert
ChildRenderObject
]. If the descendant's slot changes identity, it
/// will call [move
ChildRenderObject
]. If a descendant goes away, it will call
/// [remove
ChildRenderObject
].
///
/// These three methods should update the render tree accordingly, attaching,
/// moving, and detaching the given child render object from this element's own
...
...
@@ -5727,11 +5727,10 @@ abstract class RenderObjectElement extends Element {
@override
void
_updateSlot
(
dynamic
newSlot
)
{
final
dynamic
oldSlot
=
slot
;
assert
(
oldSlot
!=
newSlot
);
assert
(
slot
!=
newSlot
);
super
.
_updateSlot
(
newSlot
);
assert
(
slot
==
newSlot
);
_ancestorRenderObjectElement
.
move
RenderObjectChild
(
renderObject
,
oldSlo
t
,
slot
);
_ancestorRenderObjectElement
.
move
ChildRenderObject
(
renderObjec
t
,
slot
);
}
@override
...
...
@@ -5739,7 +5738,7 @@ abstract class RenderObjectElement extends Element {
assert
(
_ancestorRenderObjectElement
==
null
);
_slot
=
newSlot
;
_ancestorRenderObjectElement
=
_findAncestorRenderObjectElement
();
_ancestorRenderObjectElement
?.
insert
RenderObjectChild
(
renderObject
,
newSlot
);
_ancestorRenderObjectElement
?.
insert
ChildRenderObject
(
renderObject
,
newSlot
);
final
ParentDataElement
<
ParentData
>
parentDataElement
=
_findAncestorParentDataElement
();
if
(
parentDataElement
!=
null
)
_updateParentData
(
parentDataElement
.
widget
);
...
...
@@ -5748,59 +5747,12 @@ abstract class RenderObjectElement extends Element {
@override
void
detachRenderObject
()
{
if
(
_ancestorRenderObjectElement
!=
null
)
{
_ancestorRenderObjectElement
.
remove
RenderObjectChild
(
renderObject
,
slo
t
);
_ancestorRenderObjectElement
.
remove
ChildRenderObject
(
renderObjec
t
);
_ancestorRenderObjectElement
=
null
;
}
_slot
=
null
;
}
/// Insert the given child into [renderObject] at the given slot.
///
/// {@macro flutter.widgets.slots}
///
/// ## Deprecation
///
/// This method has been deprecated in favor of [insertRenderObjectChild].
///
/// The reason for the deprecation is to provide the `oldSlot` argument to
/// the [moveRenderObjectChild] method (such an argument was missing from
/// the now-deprecated [moveChildRenderObject] method) and the `slot`
/// argument to the [removeRenderObjectChild] method (such an argument was
/// missing from the now-deprecated [removeChildRenderObject] method). While
/// no argument was added to [insertRenderObjectChild], the name change (and
/// corresponding deprecation) was made to maintain naming parity with the
/// other two methods.
///
/// To migrate, simply override [insertRenderObjectChild] instead of
/// [insertChildRenderObject]. The arguments stay the same. Subclasses should
/// _not_ call `super.insertRenderObjectChild(...)`.
@protected
@mustCallSuper
@Deprecated
(
'Override insertRenderObjectChild instead. '
'This feature was deprecated after v1.21.0-9.0.pre.'
)
void
insertChildRenderObject
(
covariant
RenderObject
child
,
covariant
dynamic
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().'
),
]);
}());
}
/// Insert the given child into [renderObject] at the given slot.
///
/// {@template flutter.widgets.slots}
...
...
@@ -5810,9 +5762,7 @@ abstract class RenderObjectElement extends Element {
/// [IndexedSlot] is a convenient value for the slot.
/// {@endtemplate}
@protected
void
insertRenderObjectChild
(
covariant
RenderObject
child
,
covariant
dynamic
slot
)
{
insertChildRenderObject
(
child
,
slot
);
}
void
insertChildRenderObject
(
covariant
RenderObject
child
,
covariant
dynamic
slot
);
/// Move the given child to the given slot.
///
...
...
@@ -5828,127 +5778,14 @@ abstract class RenderObjectElement extends Element {
/// always having the same slot (and where children in different slots are never
/// compared against each other for the purposes of updating one slot with the
/// element from another slot) would never call this.
///
/// ## Deprecation
///
/// This method has been deprecated in favor of [moveRenderObjectChild].
///
/// The reason for the deprecation is to provide the `oldSlot` argument to
/// the [moveRenderObjectChild] method (such an argument was missing from
/// the now-deprecated [moveChildRenderObject] method) and the `slot`
/// argument to the [removeRenderObjectChild] method (such an argument was
/// missing from the now-deprecated [removeChildRenderObject] method). While
/// no argument was added to [insertRenderObjectChild], the name change (and
/// corresponding deprecation) was made to maintain naming parity with the
/// other two methods.
///
/// To migrate, simply override [moveRenderObjectChild] instead of
/// [moveChildRenderObject]. The `slot` argument becomes the `newSlot`
/// argument, and the method will now take a new `oldSlot` argument that
/// subclasses may find useful. Subclasses should _not_ call
/// `super.moveRenderObjectChild(...)`.
@protected
@mustCallSuper
@Deprecated
(
'Override moveRenderObjectChild instead. '
'This feature was deprecated after v1.21.0-9.0.pre.'
)
void
moveChildRenderObject
(
covariant
RenderObject
child
,
covariant
dynamic
slot
)
{
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().'
),
]);
}());
}
/// Move the given child from the given old slot to the given new slot.
///
/// The given child is guaranteed to have [renderObject] as its parent.
///
/// {@macro flutter.widgets.slots}
///
/// This method is only ever called if [updateChild] can end up being called
/// with an existing [Element] child and a `slot` that differs from the slot
/// that element was previously given. [MultiChildRenderObjectElement] does this,
/// for example. [SingleChildRenderObjectElement] does not (since the `slot` is
/// always null). An [Element] that has a specific set of slots with each child
/// always having the same slot (and where children in different slots are never
/// 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
)
{
moveChildRenderObject
(
child
,
newSlot
);
}
void
moveChildRenderObject
(
covariant
RenderObject
child
,
covariant
dynamic
slot
);
/// Remove the given child from [renderObject].
///
/// The given child is guaranteed to have [renderObject] as its parent.
///
/// ## Deprecation
///
/// This method has been deprecated in favor of [removeRenderObjectChild].
///
/// The reason for the deprecation is to provide the `oldSlot` argument to
/// the [moveRenderObjectChild] method (such an argument was missing from
/// the now-deprecated [moveChildRenderObject] method) and the `slot`
/// argument to the [removeRenderObjectChild] method (such an argument was
/// missing from the now-deprecated [removeChildRenderObject] method). While
/// no argument was added to [insertRenderObjectChild], the name change (and
/// corresponding deprecation) was made to maintain naming parity with the
/// other two methods.
///
/// To migrate, simply override [removeRenderObjectChild] instead of
/// [removeChildRenderObject]. The method will now take a new `slot` argument
/// that subclasses may find useful. Subclasses should _not_ call
/// `super.removeRenderObjectChild(...)`.
@protected
@mustCallSuper
@Deprecated
(
'Override removeRenderObjectChild instead. '
'This feature was deprecated after v1.21.0-9.0.pre.'
)
void
removeChildRenderObject
(
covariant
RenderObject
child
)
{
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().'
),
]);
}());
}
/// 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
dynamic
slot
)
{
removeChildRenderObject
(
child
);
}
void
removeChildRenderObject
(
covariant
RenderObject
child
);
@override
void
debugFillProperties
(
DiagnosticPropertiesBuilder
properties
)
{
...
...
@@ -6000,17 +5837,17 @@ class LeafRenderObjectElement extends RenderObjectElement {
}
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
dynamic
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
dynamic
slot
)
{
assert
(
false
);
}
@override
void
move
RenderObjectChild
(
RenderObject
child
,
dynamic
oldSlot
,
dynamic
newS
lot
)
{
void
move
ChildRenderObject
(
RenderObject
child
,
dynamic
s
lot
)
{
assert
(
false
);
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
dynamic
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
assert
(
false
);
}
...
...
@@ -6063,7 +5900,7 @@ class SingleChildRenderObjectElement extends RenderObjectElement {
}
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
dynamic
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
dynamic
slot
)
{
final
RenderObjectWithChildMixin
<
RenderObject
>
renderObject
=
this
.
renderObject
as
RenderObjectWithChildMixin
<
RenderObject
>;
assert
(
slot
==
null
);
assert
(
renderObject
.
debugValidateChild
(
child
));
...
...
@@ -6072,12 +5909,12 @@ class SingleChildRenderObjectElement extends RenderObjectElement {
}
@override
void
move
RenderObjectChild
(
RenderObject
child
,
dynamic
oldSlot
,
dynamic
newS
lot
)
{
void
move
ChildRenderObject
(
RenderObject
child
,
dynamic
s
lot
)
{
assert
(
false
);
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
dynamic
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
final
RenderObjectWithChildMixin
<
RenderObject
>
renderObject
=
this
.
renderObject
as
RenderObjectWithChildMixin
<
RenderObject
>;
assert
(
renderObject
.
child
==
child
);
renderObject
.
child
=
null
;
...
...
@@ -6121,7 +5958,7 @@ class MultiChildRenderObjectElement extends RenderObjectElement {
final
Set
<
Element
>
_forgottenChildren
=
HashSet
<
Element
>();
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
IndexedSlot
<
Element
>
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
IndexedSlot
<
Element
>
slot
)
{
final
ContainerRenderObjectMixin
<
RenderObject
,
ContainerParentDataMixin
<
RenderObject
>>
renderObject
=
this
.
renderObject
as
ContainerRenderObjectMixin
<
RenderObject
,
ContainerParentDataMixin
<
RenderObject
>>;
assert
(
renderObject
.
debugValidateChild
(
child
));
...
...
@@ -6130,16 +5967,16 @@ class MultiChildRenderObjectElement extends RenderObjectElement {
}
@override
void
move
RenderObjectChild
(
RenderObject
child
,
IndexedSlot
<
Element
>
oldSlot
,
IndexedSlot
<
Element
>
newS
lot
)
{
void
move
ChildRenderObject
(
RenderObject
child
,
IndexedSlot
<
Element
>
s
lot
)
{
final
ContainerRenderObjectMixin
<
RenderObject
,
ContainerParentDataMixin
<
RenderObject
>>
renderObject
=
this
.
renderObject
as
ContainerRenderObjectMixin
<
RenderObject
,
ContainerParentDataMixin
<
RenderObject
>>;
assert
(
child
.
parent
==
renderObject
);
renderObject
.
move
(
child
,
after:
newS
lot
?.
value
?.
renderObject
);
renderObject
.
move
(
child
,
after:
s
lot
?.
value
?.
renderObject
);
assert
(
renderObject
==
this
.
renderObject
);
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
dynamic
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
final
ContainerRenderObjectMixin
<
RenderObject
,
ContainerParentDataMixin
<
RenderObject
>>
renderObject
=
this
.
renderObject
as
ContainerRenderObjectMixin
<
RenderObject
,
ContainerParentDataMixin
<
RenderObject
>>;
assert
(
child
.
parent
==
renderObject
);
...
...
packages/flutter/lib/src/widgets/layout_builder.dart
View file @
ce40de69
...
...
@@ -156,7 +156,7 @@ class _LayoutBuilderElement<ConstraintType extends Constraints> extends RenderOb
}
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
dynamic
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
dynamic
slot
)
{
final
RenderObjectWithChildMixin
<
RenderObject
>
renderObject
=
this
.
renderObject
;
assert
(
slot
==
null
);
assert
(
renderObject
.
debugValidateChild
(
child
));
...
...
@@ -165,12 +165,12 @@ class _LayoutBuilderElement<ConstraintType extends Constraints> extends RenderOb
}
@override
void
move
RenderObjectChild
(
RenderObject
child
,
dynamic
oldSlot
,
dynamic
newS
lot
)
{
void
move
ChildRenderObject
(
RenderObject
child
,
dynamic
s
lot
)
{
assert
(
false
);
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
dynamic
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
final
RenderConstrainedLayoutBuilder
<
ConstraintType
,
RenderObject
>
renderObject
=
this
.
renderObject
;
assert
(
renderObject
.
child
==
child
);
renderObject
.
child
=
null
;
...
...
packages/flutter/lib/src/widgets/list_wheel_scroll_view.dart
View file @
ce40de69
...
...
@@ -907,7 +907,7 @@ class ListWheelElement extends RenderObjectElement implements ListWheelChildMana
}
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
int
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
int
slot
)
{
final
RenderListWheelViewport
renderObject
=
this
.
renderObject
;
assert
(
renderObject
.
debugValidateChild
(
child
));
renderObject
.
insert
(
child
as
RenderBox
,
after:
_childElements
[
slot
-
1
]?.
renderObject
as
RenderBox
);
...
...
@@ -915,7 +915,7 @@ class ListWheelElement extends RenderObjectElement implements ListWheelChildMana
}
@override
void
move
RenderObjectChild
(
RenderObject
child
,
int
oldSlot
,
int
newS
lot
)
{
void
move
ChildRenderObject
(
RenderObject
child
,
dynamic
s
lot
)
{
const
String
moveChildRenderObjectErrorMessage
=
'Currently we maintain the list in contiguous increasing order, so '
'moving children around is not allowed.'
;
...
...
@@ -923,7 +923,7 @@ class ListWheelElement extends RenderObjectElement implements ListWheelChildMana
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
int
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
assert
(
child
.
parent
==
renderObject
);
renderObject
.
remove
(
child
as
RenderBox
);
}
...
...
packages/flutter/lib/src/widgets/sliver.dart
View file @
ce40de69
...
...
@@ -1273,7 +1273,7 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render
}
@override
void
insert
RenderObjectChild
(
covariant
RenderObject
child
,
int
slot
)
{
void
insert
ChildRenderObject
(
covariant
RenderObject
child
,
int
slot
)
{
assert
(
slot
!=
null
);
assert
(
_currentlyUpdatingChildIndex
==
slot
);
assert
(
renderObject
.
debugValidateChild
(
child
));
...
...
@@ -1286,14 +1286,14 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render
}
@override
void
move
RenderObjectChild
(
covariant
RenderObject
child
,
int
oldSlot
,
int
newS
lot
)
{
assert
(
newS
lot
!=
null
);
assert
(
_currentlyUpdatingChildIndex
==
newS
lot
);
void
move
ChildRenderObject
(
covariant
RenderObject
child
,
int
s
lot
)
{
assert
(
s
lot
!=
null
);
assert
(
_currentlyUpdatingChildIndex
==
s
lot
);
renderObject
.
move
(
child
as
RenderBox
,
after:
_currentBeforeChild
);
}
@override
void
remove
RenderObjectChild
(
covariant
RenderObject
child
,
int
slot
)
{
void
remove
ChildRenderObject
(
covariant
RenderObject
child
)
{
assert
(
_currentlyUpdatingChildIndex
!=
null
);
renderObject
.
remove
(
child
as
RenderBox
);
}
...
...
packages/flutter/lib/src/widgets/sliver_persistent_header.dart
View file @
ce40de69
...
...
@@ -236,18 +236,18 @@ class _SliverPersistentHeaderElement extends RenderObjectElement {
}
@override
void
insert
RenderObjectChild
(
covariant
RenderBox
child
,
dynamic
slot
)
{
void
insert
ChildRenderObject
(
covariant
RenderBox
child
,
dynamic
slot
)
{
assert
(
renderObject
.
debugValidateChild
(
child
));
renderObject
.
child
=
child
;
}
@override
void
move
RenderObjectChild
(
covariant
RenderObject
child
,
dynamic
oldSlot
,
dynamic
newS
lot
)
{
void
move
ChildRenderObject
(
covariant
RenderObject
child
,
dynamic
s
lot
)
{
assert
(
false
);
}
@override
void
remove
RenderObjectChild
(
covariant
RenderObject
child
,
dynamic
slot
)
{
void
remove
ChildRenderObject
(
covariant
RenderObject
child
)
{
renderObject
.
child
=
null
;
}
...
...
packages/flutter/lib/src/widgets/sliver_prototype_extent_list.dart
View file @
ce40de69
...
...
@@ -75,12 +75,12 @@ class _SliverPrototypeExtentListElement extends SliverMultiBoxAdaptorElement {
static
final
Object
_prototypeSlot
=
Object
();
@override
void
insert
RenderObjectChild
(
covariant
RenderObject
child
,
covariant
dynamic
slot
)
{
void
insert
ChildRenderObject
(
covariant
RenderObject
child
,
covariant
dynamic
slot
)
{
if
(
slot
==
_prototypeSlot
)
{
assert
(
child
is
RenderBox
);
renderObject
.
child
=
child
as
RenderBox
;
}
else
{
super
.
insert
RenderObjectChild
(
child
,
slot
as
int
);
super
.
insert
ChildRenderObject
(
child
,
slot
as
int
);
}
}
...
...
@@ -91,19 +91,19 @@ class _SliverPrototypeExtentListElement extends SliverMultiBoxAdaptorElement {
}
@override
void
move
RenderObjectChild
(
RenderBox
child
,
dynamic
oldSlot
,
dynamic
newS
lot
)
{
if
(
newS
lot
==
_prototypeSlot
)
void
move
ChildRenderObject
(
RenderBox
child
,
dynamic
s
lot
)
{
if
(
s
lot
==
_prototypeSlot
)
assert
(
false
);
// There's only one prototype child so it cannot be moved.
else
super
.
move
RenderObjectChild
(
child
,
oldSlot
as
int
,
newS
lot
as
int
);
super
.
move
ChildRenderObject
(
child
,
s
lot
as
int
);
}
@override
void
remove
RenderObjectChild
(
RenderBox
child
,
dynamic
slot
)
{
void
remove
ChildRenderObject
(
RenderBox
child
)
{
if
(
renderObject
.
child
==
child
)
renderObject
.
child
=
null
;
else
super
.
remove
RenderObjectChild
(
child
,
slot
as
int
);
super
.
remove
ChildRenderObject
(
child
);
}
@override
...
...
packages/flutter/lib/src/widgets/table.dart
View file @
ce40de69
...
...
@@ -303,16 +303,16 @@ class _TableElement extends RenderObjectElement {
}
@override
void
insert
RenderObjectChild
(
RenderObject
child
,
IndexedSlot
<
Element
>
slot
)
{
void
insert
ChildRenderObject
(
RenderObject
child
,
IndexedSlot
<
Element
>
slot
)
{
renderObject
.
setupParentData
(
child
);
}
@override
void
move
RenderObjectChild
(
RenderObject
child
,
IndexedSlot
<
Element
>
oldSlot
,
IndexedSlot
<
Element
>
newS
lot
)
{
void
move
ChildRenderObject
(
RenderObject
child
,
dynamic
s
lot
)
{
}
@override
void
remove
RenderObjectChild
(
RenderObject
child
,
IndexedSlot
<
Element
>
slot
)
{
void
remove
ChildRenderObject
(
RenderObject
child
)
{
final
TableCellParentData
childParentData
=
child
.
parentData
as
TableCellParentData
;
renderObject
.
setChild
(
childParentData
.
x
,
childParentData
.
y
,
null
);
}
...
...
packages/flutter/test/widgets/render_object_element_test.dart
deleted
100644 → 0
View file @
d9188c19
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
@immutable
class
Pair
<
T
>
{
const
Pair
(
this
.
first
,
this
.
second
);
final
T
first
;
final
T
second
;
@override
bool
operator
==(
Object
other
)
{
return
other
is
Pair
<
T
>
&&
other
.
first
==
first
&&
other
.
second
==
second
;
}
@override
int
get
hashCode
=>
hashValues
(
first
,
second
);
@override
String
toString
()
=>
'(
$first
,
$second
)'
;
}
/// Widget that will layout one child in the top half of this widget's size
/// and the other child in the bottom half. It will swap which child is on top
/// and which is on bottom every time the widget is rendered.
abstract
class
Swapper
extends
RenderObjectWidget
{
const
Swapper
({
this
.
stable
,
this
.
swapper
});
final
Widget
stable
;
final
Widget
swapper
;
@override
SwapperElement
createElement
();
@override
RenderObject
createRenderObject
(
BuildContext
context
)
=>
RenderSwapper
();
}
class
SwapperWithProperOverrides
extends
Swapper
{
const
SwapperWithProperOverrides
({
Widget
stable
,
Widget
swapper
,
})
:
super
(
stable:
stable
,
swapper:
swapper
);
@override
SwapperElement
createElement
()
=>
SwapperElementWithProperOverrides
(
this
);
}
class
SwapperWithNoOverrides
extends
Swapper
{
const
SwapperWithNoOverrides
({
Widget
stable
,
Widget
swapper
,
})
:
super
(
stable:
stable
,
swapper:
swapper
);
@override
SwapperElement
createElement
()
=>
SwapperElementWithNoOverrides
(
this
);
}
class
SwapperWithDeprecatedOverrides
extends
Swapper
{
const
SwapperWithDeprecatedOverrides
({
Widget
stable
,
Widget
swapper
,
})
:
super
(
stable:
stable
,
swapper:
swapper
);
@override
SwapperElement
createElement
()
=>
SwapperElementWithDeprecatedOverrides
(
this
);
}
abstract
class
SwapperElement
extends
RenderObjectElement
{
SwapperElement
(
Swapper
widget
)
:
super
(
widget
);
Element
stable
;
Element
swapper
;
bool
swapperIsOnTop
=
true
;
List
<
dynamic
>
insertSlots
=
<
dynamic
>[];
List
<
Pair
<
dynamic
>>
moveSlots
=
<
Pair
<
dynamic
>>[];
List
<
dynamic
>
removeSlots
=
<
dynamic
>[];
@override
Swapper
get
widget
=>
super
.
widget
as
Swapper
;
@override
RenderSwapper
get
renderObject
=>
super
.
renderObject
as
RenderSwapper
;
@override
void
visitChildren
(
ElementVisitor
visitor
)
{
if
(
stable
!=
null
)
visitor
(
stable
);
if
(
swapper
!=
null
)
visitor
(
swapper
);
}
@override
void
update
(
Swapper
newWidget
)
{
super
.
update
(
newWidget
);
_updateChildren
(
newWidget
);
}
@override
void
mount
(
Element
parent
,
dynamic
newSlot
)
{
super
.
mount
(
parent
,
newSlot
);
_updateChildren
(
widget
);
}
void
_updateChildren
(
Swapper
widget
)
{
stable
=
updateChild
(
stable
,
widget
.
stable
,
'stable'
);
swapper
=
updateChild
(
swapper
,
widget
.
swapper
,
swapperIsOnTop
);
swapperIsOnTop
=
!
swapperIsOnTop
;
}
}
class
SwapperElementWithProperOverrides
extends
SwapperElement
{
SwapperElementWithProperOverrides
(
Swapper
widget
)
:
super
(
widget
);
@override
void
insertRenderObjectChild
(
RenderBox
child
,
dynamic
slot
)
{
insertSlots
.
add
(
slot
);
assert
(
child
!=
null
);
if
(
slot
==
'stable'
)
renderObject
.
stable
=
child
;
else
renderObject
.
setSwapper
(
child
,
slot
as
bool
);
}
@override
void
moveRenderObjectChild
(
RenderBox
child
,
bool
oldIsOnTop
,
bool
newIsOnTop
)
{
moveSlots
.
add
(
Pair
<
bool
>(
oldIsOnTop
,
newIsOnTop
));
assert
(
oldIsOnTop
==
!
newIsOnTop
);
renderObject
.
setSwapper
(
child
,
newIsOnTop
);
}
@override
void
removeRenderObjectChild
(
RenderBox
child
,
dynamic
slot
)
{
removeSlots
.
add
(
slot
);
if
(
slot
==
'stable'
)
renderObject
.
stable
=
null
;
else
renderObject
.
setSwapper
(
null
,
slot
as
bool
);
}
}
class
SwapperElementWithNoOverrides
extends
SwapperElement
{
SwapperElementWithNoOverrides
(
Swapper
widget
)
:
super
(
widget
);
}
class
SwapperElementWithDeprecatedOverrides
extends
SwapperElement
{
SwapperElementWithDeprecatedOverrides
(
Swapper
widget
)
:
super
(
widget
);
@override
// ignore: must_call_super
void
insertChildRenderObject
(
RenderBox
child
,
dynamic
slot
)
{
insertSlots
.
add
(
slot
);
assert
(
child
!=
null
);
if
(
slot
==
'stable'
)
renderObject
.
stable
=
child
;
else
renderObject
.
setSwapper
(
child
,
slot
as
bool
);
}
@override
// ignore: must_call_super
void
moveChildRenderObject
(
RenderBox
child
,
bool
isOnTop
)
{
moveSlots
.
add
(
Pair
<
bool
>(
null
,
isOnTop
));
renderObject
.
setSwapper
(
child
,
isOnTop
);
}
@override
// ignore: must_call_super
void
removeChildRenderObject
(
RenderBox
child
)
{
removeSlots
.
add
(
null
);
if
(
child
==
renderObject
.
_stable
)
renderObject
.
stable
=
null
;
else
renderObject
.
setSwapper
(
null
,
swapperIsOnTop
);
}
}
class
RenderSwapper
extends
RenderBox
{
RenderBox
_stable
;
RenderBox
get
stable
=>
_stable
;
set
stable
(
RenderBox
child
)
{
if
(
child
==
_stable
)
return
;
if
(
_stable
!=
null
)
dropChild
(
_stable
);
_stable
=
child
;
if
(
child
!=
null
)
adoptChild
(
child
);
}
bool
_swapperIsOnTop
;
RenderBox
_swapper
;
RenderBox
get
swapper
=>
_swapper
;
void
setSwapper
(
RenderBox
child
,
bool
isOnTop
)
{
if
(
isOnTop
!=
_swapperIsOnTop
)
{
_swapperIsOnTop
=
isOnTop
;
markNeedsLayout
();
}
if
(
child
==
_swapper
)
return
;
if
(
_swapper
!=
null
)
dropChild
(
_swapper
);
_swapper
=
child
;
if
(
child
!=
null
)
adoptChild
(
child
);
}
@override
void
visitChildren
(
RenderObjectVisitor
visitor
)
{
if
(
_stable
!=
null
)
visitor
(
_stable
);
if
(
_swapper
!=
null
)
visitor
(
_swapper
);
}
@override
void
attach
(
PipelineOwner
owner
)
{
super
.
attach
(
owner
);
visitChildren
((
RenderObject
child
)
=>
child
.
attach
(
owner
));
}
@override
void
detach
()
{
super
.
detach
();
visitChildren
((
RenderObject
child
)
=>
child
.
detach
());
}
@override
void
performLayout
()
{
assert
(
constraints
.
hasBoundedWidth
);
assert
(
constraints
.
hasTightHeight
);
size
=
constraints
.
biggest
;
const
Offset
topOffset
=
Offset
.
zero
;
final
Offset
bottomOffset
=
Offset
(
0
,
size
.
height
/
2
);
final
BoxConstraints
childConstraints
=
constraints
.
copyWith
(
minHeight:
constraints
.
minHeight
/
2
,
maxHeight:
constraints
.
maxHeight
/
2
,
);
if
(
_stable
!=
null
)
{
final
BoxParentData
stableParentData
=
_stable
.
parentData
as
BoxParentData
;
_stable
.
layout
(
childConstraints
);
stableParentData
.
offset
=
_swapperIsOnTop
?
bottomOffset
:
topOffset
;
}
if
(
_swapper
!=
null
)
{
final
BoxParentData
swapperParentData
=
_swapper
.
parentData
as
BoxParentData
;
_swapper
.
layout
(
childConstraints
);
swapperParentData
.
offset
=
_swapperIsOnTop
?
topOffset
:
bottomOffset
;
}
}
@override
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
visitChildren
((
RenderObject
child
)
{
final
BoxParentData
childParentData
=
child
.
parentData
as
BoxParentData
;
context
.
paintChild
(
child
,
offset
+
childParentData
.
offset
);
});
}
@override
void
redepthChildren
()
{
visitChildren
((
RenderObject
child
)
=>
redepthChild
(
child
));
}
}
BoxParentData
parentDataFor
(
RenderObject
renderObject
)
=>
renderObject
.
parentData
as
BoxParentData
;
void
main
(
)
{
testWidgets
(
'RenderObjectElement *RenderObjectChild methods get called with correct arguments'
,
(
WidgetTester
tester
)
async
{
const
Key
redKey
=
ValueKey
<
String
>(
'red'
);
const
Key
blueKey
=
ValueKey
<
String
>(
'blue'
);
Widget
widget
()
{
return
SwapperWithProperOverrides
(
stable:
ColoredBox
(
key:
redKey
,
color:
Color
(
nonconst
(
0xffff0000
)),
),
swapper:
ColoredBox
(
key:
blueKey
,
color:
Color
(
nonconst
(
0xff0000ff
)),
),
);
}
await
tester
.
pumpWidget
(
widget
());
final
SwapperElement
swapper
=
tester
.
element
<
SwapperElement
>(
find
.
byType
(
SwapperWithProperOverrides
));
final
RenderBox
redBox
=
tester
.
renderObject
<
RenderBox
>(
find
.
byKey
(
redKey
));
final
RenderBox
blueBox
=
tester
.
renderObject
<
RenderBox
>(
find
.
byKey
(
blueKey
));
expect
(
swapper
.
insertSlots
.
length
,
2
);
expect
(
swapper
.
insertSlots
,
contains
(
'stable'
));
expect
(
swapper
.
insertSlots
,
contains
(
true
));
expect
(
swapper
.
moveSlots
,
isEmpty
);
expect
(
swapper
.
removeSlots
,
isEmpty
);
expect
(
parentDataFor
(
redBox
).
offset
,
const
Offset
(
0
,
300
));
expect
(
parentDataFor
(
blueBox
).
offset
,
Offset
.
zero
);
await
tester
.
pumpWidget
(
widget
());
expect
(
swapper
.
insertSlots
.
length
,
2
);
expect
(
swapper
.
moveSlots
.
length
,
1
);
expect
(
swapper
.
moveSlots
,
contains
(
const
Pair
<
bool
>(
true
,
false
)));
expect
(
swapper
.
removeSlots
,
isEmpty
);
expect
(
parentDataFor
(
redBox
).
offset
,
Offset
.
zero
);
expect
(
parentDataFor
(
blueBox
).
offset
,
const
Offset
(
0
,
300
));
await
tester
.
pumpWidget
(
const
SwapperWithProperOverrides
());
expect
(
redBox
.
attached
,
false
);
expect
(
blueBox
.
attached
,
false
);
expect
(
swapper
.
insertSlots
.
length
,
2
);
expect
(
swapper
.
moveSlots
.
length
,
1
);
expect
(
swapper
.
removeSlots
.
length
,
2
);
expect
(
swapper
.
removeSlots
,
contains
(
'stable'
));
expect
(
swapper
.
removeSlots
,
contains
(
false
));
});
testWidgets
(
'RenderObjectElement *RenderObjectChild methods delegate to deprecated methods'
,
(
WidgetTester
tester
)
async
{
const
Key
redKey
=
ValueKey
<
String
>(
'red'
);
const
Key
blueKey
=
ValueKey
<
String
>(
'blue'
);
Widget
widget
()
{
return
SwapperWithDeprecatedOverrides
(
stable:
ColoredBox
(
key:
redKey
,
color:
Color
(
nonconst
(
0xffff0000
)),
),
swapper:
ColoredBox
(
key:
blueKey
,
color:
Color
(
nonconst
(
0xff0000ff
)),
),
);
}
await
tester
.
pumpWidget
(
widget
());
final
SwapperElement
swapper
=
tester
.
element
<
SwapperElement
>(
find
.
byType
(
SwapperWithDeprecatedOverrides
));
final
RenderBox
redBox
=
tester
.
renderObject
<
RenderBox
>(
find
.
byKey
(
redKey
));
final
RenderBox
blueBox
=
tester
.
renderObject
<
RenderBox
>(
find
.
byKey
(
blueKey
));
expect
(
swapper
.
insertSlots
.
length
,
2
);
expect
(
swapper
.
insertSlots
,
contains
(
'stable'
));
expect
(
swapper
.
insertSlots
,
contains
(
true
));
expect
(
swapper
.
moveSlots
,
isEmpty
);
expect
(
swapper
.
removeSlots
,
isEmpty
);
expect
(
parentDataFor
(
redBox
).
offset
,
const
Offset
(
0
,
300
));
expect
(
parentDataFor
(
blueBox
).
offset
,
Offset
.
zero
);
await
tester
.
pumpWidget
(
widget
());
expect
(
swapper
.
insertSlots
.
length
,
2
);
expect
(
swapper
.
moveSlots
.
length
,
1
);
expect
(
swapper
.
moveSlots
,
contains
(
const
Pair
<
bool
>(
null
,
false
)));
expect
(
swapper
.
removeSlots
,
isEmpty
);
expect
(
parentDataFor
(
redBox
).
offset
,
Offset
.
zero
);
expect
(
parentDataFor
(
blueBox
).
offset
,
const
Offset
(
0
,
300
));
await
tester
.
pumpWidget
(
const
SwapperWithDeprecatedOverrides
());
expect
(
redBox
.
attached
,
false
);
expect
(
blueBox
.
attached
,
false
);
expect
(
swapper
.
insertSlots
.
length
,
2
);
expect
(
swapper
.
moveSlots
.
length
,
1
);
expect
(
swapper
.
removeSlots
.
length
,
2
);
expect
(
swapper
.
removeSlots
,
<
bool
>[
null
,
null
]);
});
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'
));
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment