gpt4 book ai didi

dart - CustomPaint和FittedBox

转载 作者:行者123 更新时间:2023-12-03 02:48:20 25 4
gpt4 key购买 nike

如何将CustomPaint设置为父窗口小部件?

return new Container(
color: Color(0xfffff4f0),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
new Expanded(
flex: 6,
child: FittedBox(
fit: BoxFit.contain,
child: widget CustomePaint() // Containers(),

)),
new Expanded(
flex: 4,
)
)
)

适合:BoxFit.contain适用于
    Container(
height: 30,
width: 10
)

但不适用于在 Canvas 矩形上绘制的CustomePaint():
canvas.drawRect(new Rect.fromLTWH(0, 0, 10 , 30), new Paint()..color = 
Colors.red);

enter image description here

最佳答案

看来您只提供了所需代码的一部分。
我已经尝试过几乎您的代码,并且效果很好。我使用了另一种颜色,并在CustomPaint中添加了边框,以更好地查看其绘制位置。


Widget getRootView() {
return Container(
color: Colors.green,
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisSize: MainAxisSize.max, children: <Widget>[
Expanded(
flex: 2,
child: CustomPaint(painter: Painter3()),
),
Expanded(
flex: 1,
child: Container(
color: Colors.red,
child: Center(child: Text("3")),
),
)
]));
}

class Painter3 extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
canvas.drawRect(Offset(10, 10) & Size(size.width - 20, size.height - 20), Paint()..color = Colors.blue);
}

@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}

我在这里得到的是: The result of the code above

关于dart - CustomPaint和FittedBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54876468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com