Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Why can't I change suffixIcon size

I want to customize the Icon on the right of TextField, but the size of the Icon cannot be changed after using Image. If I use Icon, I can change it, why? What can I do to use custom images and resize them?

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,
                        ),
                      ),
                    ),
                  ),
                ),
like image 251
盐渍旳鱼丶 Avatar asked Nov 27 '22 08:11

盐渍旳鱼丶


2 Answers

You can now resize the suffixIcon with suffixIconConstraints

decoration: InputDecoration(
                    suffixIconConstraints: BoxConstraints(
                      minHeight: 24,
                      minWidth: 24
                    ),
                      suffixIcon: Icon(Icons.arrow_drop_down_sharp, color: AppColors.heather),);
like image 85
Balaji Avatar answered Dec 11 '22 14:12

Balaji


This problem has been solved.

Add the padding in the Container.

The following code:

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,
                    ),
                  ),
                ),
              ),
            ),
like image 43
盐渍旳鱼丶 Avatar answered Dec 11 '22 14:12

盐渍旳鱼丶