FrogJar(
child: FrogSize(
size: Size(20, 20),
child: Text('hello'),
),
decoration: BoxDecoration(color: Colors.red),
)
class FrogSize extends ParentDataWidget<FrogJar> {
FrogSize({
Key key,
@required this.size,
@required Widget child,
}) : assert(child != null),
assert(size != null),
super(key: key, child: child);
final Size size;
@override
void applyParentData(RenderObject renderObject) {
///Text 的 renderobject
final FrogJarParentData parentData = renderObject.parentData;
if (parentData.size != size) {
parentData.size = size;
final RenderFrogJar targetParent = renderObject.parent;
targetParent.markNeedsLayout();
}
}
}
class FrogJar extends DecoratedBox {
const FrogJar({
Key key,
@required Decoration decoration,
Widget child,
}) : assert(decoration != null),
super(key: key, child: child, decoration: decoration);
@override
RenderDecoratedBox createRenderObject(BuildContext context) {
return RenderFrogJar(
decoration: decoration,
position: position,
configuration: createLocalImageConfiguration(context),
);
}
}
class RenderFrogJar extends RenderDecoratedBox {
RenderFrogJar({
@required Decoration decoration,
DecorationPosition position = DecorationPosition.background,
ImageConfiguration configuration = ImageConfiguration.empty,
RenderBox child,
}) : assert(decoration != null),
assert(position != null),
assert(configuration != null),
super(
decoration: decoration,
position: position,
configuration: configuration,
);
@override
void setupParentData(RenderObject child) {
///child是Text的RenderObject
FrogJarParentData frogJarParentData = FrogJarParentData();
frogJarParentData.size = Size(10, 10);
child.parentData = frogJarParentData;
}
}
class FrogJarParentData extends ParentData {
Size size;
}
ParentDataWidget用法
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- shall疑问句可用于第一人称和第三人称例句具体看书 用于第二、三人称陈述句中1、表示“命令” 在法律条文、规章制...
- 每年到这个时候,身边就会有很多人开始咳嗽、咳痰、流鼻涕、打喷嚏的,有些是感冒、有些是哮喘、有些是气管炎,有些的鼻炎...
- 有些时候作为警告视图的小弹窗 ,能够实现的功能还是很全面的: 当然声明肯定是 import UIKit ,这个不必...