@@ -2,11 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flutter code sample for [SlottedMultiChildRenderObjectWidgetMixin].
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
/// Flutter code sample for [SlottedMultiChildRenderObjectWidgetMixin].
|
||||
|
||||
/// Slots used for the children of [Diagonal] and [RenderDiagonal].
|
||||
enum DiagonalSlot {
|
||||
topLeft,
|
||||
@@ -69,7 +69,8 @@ class Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWidg
|
||||
/// A render object that demonstrates the usage of
|
||||
/// [SlottedContainerRenderObjectMixin] by providing slots for two children that
|
||||
/// will be arranged diagonally.
|
||||
class RenderDiagonal extends RenderBox with SlottedContainerRenderObjectMixin<DiagonalSlot>, DebugOverflowIndicatorMixin {
|
||||
class RenderDiagonal extends RenderBox
|
||||
with SlottedContainerRenderObjectMixin<DiagonalSlot>, DebugOverflowIndicatorMixin {
|
||||
RenderDiagonal({Color? backgroundColor}) : _backgroundColor = backgroundColor;
|
||||
|
||||
// Getters and setters to configure the [RenderObject] with the configuration
|
||||
@@ -100,10 +101,8 @@ class RenderDiagonal extends RenderBox with SlottedContainerRenderObjectMixin<Di
|
||||
@override
|
||||
Iterable<RenderBox> get children {
|
||||
return <RenderBox>[
|
||||
if (_topLeft != null)
|
||||
_topLeft!,
|
||||
if (_bottomRight != null)
|
||||
_bottomRight!,
|
||||
if (_topLeft != null) _topLeft!,
|
||||
if (_bottomRight != null) _bottomRight!,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -157,8 +156,7 @@ class RenderDiagonal extends RenderBox with SlottedContainerRenderObjectMixin<Di
|
||||
if (backgroundColor != null) {
|
||||
context.canvas.drawRect(
|
||||
offset & size,
|
||||
Paint()
|
||||
..color = backgroundColor!,
|
||||
Paint()..color = backgroundColor!,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -193,7 +191,7 @@ class RenderDiagonal extends RenderBox with SlottedContainerRenderObjectMixin<Di
|
||||
// HIT TEST
|
||||
|
||||
@override
|
||||
bool hitTestChildren(BoxHitTestResult result, { required Offset position }) {
|
||||
bool hitTestChildren(BoxHitTestResult result, {required Offset position}) {
|
||||
for (final RenderBox child in children) {
|
||||
final BoxParentData parentData = child.parentData! as BoxParentData;
|
||||
final bool isHit = result.addWithPaintOffset(
|
||||
@@ -226,7 +224,8 @@ class RenderDiagonal extends RenderBox with SlottedContainerRenderObjectMixin<Di
|
||||
double computeMaxIntrinsicWidth(double height) {
|
||||
final double topLeftWidth = _topLeft?.getMaxIntrinsicWidth(double.infinity) ?? 0;
|
||||
final double bottomRightWith = _bottomRight?.getMaxIntrinsicWidth(double.infinity) ?? 0;
|
||||
return topLeftWidth + bottomRightWith; }
|
||||
return topLeftWidth + bottomRightWith;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicHeight(double width) {
|
||||
|
||||
Reference in New Issue
Block a user