我使用 customPainter 小部件绘制自定义小部件,但无法在列小部件中扩展它。我在这里看到过类似的问题,但即使CrossAxisAlignment.stretch
我也遇到了问题。当我使用Expanded
小部件而不是Flexible
小部件时,出现编译错误。正如您所看到的,小部件不关心自定义小部件,而是在 customPaint 上绘制底部卡片文本。
我试图扩展的 CardView 小部件扩展了 CustomPaint,没有子项,所有内容都是使用画布上的 CustomPainter 绘制的,在CustomPainter.paint(canvas, size)
.
在paint(canvas, size)
方法中,当我打印size.height
i get 0.0 时,这解释了为什么文本底部打印在小部件上。
小部件代码:
class CardViewState extends State<CardView> {
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Padding(
padding: new EdgeInsets.all(10.0),
child: new Text(
"CARD TOP",
//widget.card.name,
style: new TextStyle(
fontSize: 25.0,
color: Colors.black,
fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
new Flexible(
child: new …
Run Code Online (Sandbox Code Playgroud) 我如何知道我的 Web Flutter 应用程序是在桌面上还是在移动设备上运行?我无法使用 kIsWeb,因为它表示应用程序是否是为网络构建的,而不是它是否在网络上运行。谢谢。