Flutter:为什么我不能更改suffixIcon的大小

10

我想自定义TextField右侧的图标,但使用Image后无法更改图标大小。如果使用Icon,则可以更改大小,为什么?我该如何使用自定义图像并调整其大小?

new TextField(
                  decoration: InputDecoration(
                    hintText: '请输入密码',
                    suffixIcon: new GestureDetector(
                      onTap: () {},
                      child: new Container(
                        color: Colors.cyan,
                        child: Image(
                          image: AssetImage(
                            'images/login/icon_show_sel.png',
                          ),
                          height: 20,
                          width: 20,
                        ),
                      ),
                    ),
                  ),
                ),
6个回答

37

现在您可以使用 suffixIconConstraints 调整后缀图标的大小。

decoration: InputDecoration(
                    suffixIconConstraints: BoxConstraints(
                      minHeight: 24,
                      minWidth: 24
                    ),
                      suffixIcon: Icon(Icons.arrow_drop_down_sharp, color: AppColors.heather),);

1
在我看来,他们决定如何实现这一点有点奇怪/复杂。但是这帮助我去掉了后缀图标的填充。谢谢! - Tom O

13

这个问题已经解决。

在容器中添加填充。

以下代码:

new TextField(
              decoration: InputDecoration(
                hintText: '请输入密码',
                suffixIcon: new GestureDetector(
                  onTap: () {},
                  child: new Container(
                    padding: EdgeInsets.symmetric(vertical: 10),
                    child: Image(
                      image: AssetImage(
                        'images/login/icon_show_sel.png',
                      ),
                      height: 20,
                      width: 20,
                    ),
                  ),
                ),
              ),
            ),

13

suffixIcon小部件包装在一个UnconstrainedBox中。


谢谢,兄弟。这个在SvgPicture.asset()中运行得很好。 - Fuad Reza
谢谢,兄弟。这个在SvgPicture.asset()函数中运行得很好。 - undefined

3
TextField(
decoration: InputDecoration(
    hintText: '请输入密码',
    suffixIcon: new GestureDetector(
        onTap: () {},
        child: Container(
            padding: EdgeInsets.all(15.0),
            color: Colors.cyan,
            constraints: BoxConstraints(
            maxHeight: 10.0,
            maxWidth: 10.0,
            ),
            child: Image(
                image: AssetImage(
                'images/login/icon_show_sel.png',
                ),
                height: 20,
                width: 20,
            ),
        )
    ),
),

),


0

只需使用Container将您的小部件包装起来,并设置其宽度属性即可。

TextField(
decoration: InputDecoration(
    hintText: 'Enter Name',
    suffixIcon:Container(
        width:100 //Set it according to your need
        color: Colors.cyan,
        child: Image.asset(...)
      )
   ),
),

0

非常简单

suffixIcon: Icon(Icons.location_searching, size: 60,),

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接