首页 > 解决方案 > 如何包含带有子图像的 FlatButton UI?

问题描述

我想让我的图像像容器 FlatButton 的大小

这是我的代码

child: FlatButton(
     child: canRoll
           ? Image.asset( '/images/wRoll.png', fit: BoxFit.contain,)
           : Image.asset('/images/wNoRoll.png',fit: BoxFit.contain,),

有没有办法让我的图像尺寸更大?或响应我的 FlatButton?

标签: flutter

解决方案


你可以试试这段代码:

Container(child: ConstrainedBox(
constraints: BoxConstraints.expand(),
child: FlatButton(
         onPressed: null,
         padding: EdgeInsets.all(0.0),
         child: canRoll ? Image.asset('images/wRoll.png')
                        : Image.asset('images/wNoRoll.png')
       ) //FlatButton
    ) //ConstrainedBox
 ) //Container

将填充设置为零应该会有所帮助。


推荐阅读