Unverified Commit 30adac1a authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Updating example for MultiChildLayoutDelegate (#15597)

parent f2ffc8de
...@@ -41,26 +41,43 @@ class MultiChildLayoutParentData extends ContainerBoxParentData<RenderBox> { ...@@ -41,26 +41,43 @@ class MultiChildLayoutParentData extends ContainerBoxParentData<RenderBox> {
/// Used with [CustomMultiChildLayout], the widget for the /// Used with [CustomMultiChildLayout], the widget for the
/// [RenderCustomMultiChildLayoutBox] render object. /// [RenderCustomMultiChildLayoutBox] render object.
/// ///
/// ## Example /// Each child must be wrapped in a [LayoutId] widget to assign the id that
/// identifies it to the delegate. The [LayoutId.id] needs to be unique among
/// the children that the [CustomMultiChildLayout] manages.
///
/// ## Sample code
/// ///
/// Below is an example implementation of [performLayout] that causes one widget /// Below is an example implementation of [performLayout] that causes one widget
/// to be the same size as another: /// (the follower) to be the same size as another (the leader):
/// ///
/// ```dart /// ```dart
/// @override /// // Define your own slot numbers, depending upon the id assigned by LayoutId.
/// void performLayout(Size size) { /// // Typical usage is to define an enum like the one below, and use those
/// Size followerSize = Size.zero; /// // values as the ids.
/// /// enum _Slot {
/// if (hasChild(_Slots.leader) { /// leader,
/// followerSize = layoutChild(_Slots.leader, new BoxConstraints.loose(size)); /// follower,
/// positionChild(_Slots.leader, Offset.zero); /// }
/// } ///
/// /// class FollowTheLeader extends MultiChildLayoutDelegate {
/// if (hasChild(_Slots.follower)) { /// @override
/// layoutChild(_Slots.follower, new BoxConstraints.tight(followerSize)); /// void performLayout(Size size) {
/// positionChild(_Slots.follower, new Offset(size.width - followerSize.width, /// Size leaderSize = Size.zero;
/// size.height - followerSize.height)); ///
/// if (hasChild(_Slot.leader)) {
/// leaderSize = layoutChild(_Slot.leader, new BoxConstraints.loose(size));
/// positionChild(_Slot.leader, Offset.zero);
/// }
///
/// if (hasChild(_Slot.follower)) {
/// layoutChild(_Slot.follower, new BoxConstraints.tight(leaderSize));
/// positionChild(_Slot.follower, new Offset(size.width - leaderSize.width,
/// size.height - leaderSize.height));
/// }
/// } /// }
///
/// @override
/// bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) => false;
/// } /// }
/// ``` /// ```
/// ///
......
...@@ -1448,7 +1448,7 @@ class CustomSingleChildLayout extends SingleChildRenderObjectWidget { ...@@ -1448,7 +1448,7 @@ class CustomSingleChildLayout extends SingleChildRenderObjectWidget {
} }
} }
/// Meta data for identifying children in a [CustomMultiChildLayout]. /// Metadata for identifying children in a [CustomMultiChildLayout].
/// ///
/// The [MultiChildLayoutDelegate.hasChild], /// The [MultiChildLayoutDelegate.hasChild],
/// [MultiChildLayoutDelegate.layoutChild], and /// [MultiChildLayoutDelegate.layoutChild], and
...@@ -1466,6 +1466,9 @@ class LayoutId extends ParentDataWidget<CustomMultiChildLayout> { ...@@ -1466,6 +1466,9 @@ class LayoutId extends ParentDataWidget<CustomMultiChildLayout> {
super(key: key ?? new ValueKey<Object>(id), child: child); super(key: key ?? new ValueKey<Object>(id), child: child);
/// An object representing the identity of this child. /// An object representing the identity of this child.
///
/// The [id] needs to be unique among the children that the
/// [CustomMultiChildLayout] manages.
final Object id; final Object id;
@override @override
......
...@@ -4462,13 +4462,17 @@ abstract class RenderObjectElement extends Element { ...@@ -4462,13 +4462,17 @@ abstract class RenderObjectElement extends Element {
@override @override
void deactivate() { void deactivate() {
super.deactivate(); super.deactivate();
assert(!renderObject.attached); assert(!renderObject.attached,
'A RenderObject was still attached when attempting to deactivate its '
'RenderObjectElement: $renderObject');
} }
@override @override
void unmount() { void unmount() {
super.unmount(); super.unmount();
assert(!renderObject.attached); assert(!renderObject.attached,
'A RenderObject was still attached when attempting to unmount its '
'RenderObjectElement: $renderObject');
widget.didUnmountRenderObject(renderObject); widget.didUnmountRenderObject(renderObject);
} }
......
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