- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何将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,
)
)
)
Container(
height: 30,
width: 10
)
canvas.drawRect(new Rect.fromLTWH(0, 0, 10 , 30), new Paint()..color =
Colors.red);
最佳答案
看来您只提供了所需代码的一部分。
我已经尝试过几乎您的代码,并且效果很好。我使用了另一种颜色,并在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;
}
}
我在这里得到的是:
关于dart - CustomPaint和FittedBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54876468/
我正在尝试使固定宽度框中的所有文本(长度不同)适合,并且我希望它们在应用 FittedBox 时看起来与最长单词的大小相同。所以我正在做的是用空白填充单词的其余部分,以使长度与最长的单词相匹配。但这并
我经常会在 SizedBox 中设计小部件,这样我就可以调整字体大小和填充以获得精确的外观。 然后,无论我在哪里使用这些 SizedBox 小部件之一,我都会将它们包装在一个 FittedBox 中,
使用 FittedBox 时,文本大小与文本长度相比变得非常小。我不希望文字缩小。相反,我希望文本保持相同的大小并且只适合适合的部分。 Container( width: 250, child:
我希望将一个文本小部件的字体大小基于另一个。如果我将文本小部件放入 FittedBox 并填充到容器中,文本小部件将变为相同大小,但字体因字符串长度而不同。有没有什么办法可以在一个文本小部件被一个合适
我正在创建一个 flutter 聊天应用程序,我希望我的消息根据文本小部件的宽度(短/长文本)灵活。 我有一列小部件,我希望消息文本确定同一列中所有其他小部件的最大宽度。 我会用一些屏幕截图更好地解释
在下面的示例中,FittedBox 执行了我想要的操作:它将高度适合容器。但是,它应该隐藏图像的其余部分。但是,它会呈现它。 出了什么问题? /// Flutter code sample for E
在下面的示例中,FittedBox 执行了我想要的操作:它将高度适合容器。但是,它应该隐藏图像的其余部分。但是,它会呈现它。 出了什么问题? /// Flutter code sample for E
当我将 Image.network 放置在作为 FittedBox 子项的 Row 或 Container 中时,查看它会导致错误/崩溃。 FittedBox 实际上使用一个函数作为其子项,该函数根据
我是一名优秀的程序员,十分优秀!