RenderBox提供了覆盖paint()方法的机会。但是如何从该RenderBox构建()小部件?
答案 0 :(得分:1)
可以代替StatefulWidget
或StatelessWidget
的子类SingleChildRenderObjectWidget
(或类似的子类)
class MyWidget extends SingleChildRenderObjectWidget {
@override
MyRenderBox createRenderObject(BuildContext context) {
return new MyRenderBox(title: "bar");
}
@override
void updateRenderObject(BuildContext context, MyRenderBox renderObject) {
renderObject.title = "foo";
}
}
class MyRenderBox extends RenderBox {
String title;
MyRenderBox({this.title});
}
其他一些有趣的子类是LeafRenderObjectWidget
和MultiChildRenderObjectWidget