盐渍旳鱼丶
盐渍旳鱼丶

Reputation: 279

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,
                        ),
                      ),
                    ),
                  ),
                ),

Upvotes: 14

Views: 19375

Answers (6)

Musfiq Shanta
Musfiq Shanta

Reputation: 1615

Very simple

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

Upvotes: 0

Ahmad hassan
Ahmad hassan

Reputation: 1009

Simply Wrap you Widget with Container and set width property to it

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

Upvotes: 1

Koofng
Koofng

Reputation: 202

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,
            ),
        )
    ),
),

),

Upvotes: 3

Balaji
Balaji

Reputation: 2077

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),);

Upvotes: 45

Popeye
Popeye

Reputation: 521

wrap suffixIcon widget in an UnconstrainedBox.

Upvotes: 23

盐渍旳鱼丶
盐渍旳鱼丶

Reputation: 279

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,
                    ),
                  ),
                ),
              ),
            ),

Upvotes: 13

Related Questions