Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to size an icon according to parent in flutter

I want to size an icon inside a container to be the size of that container so that it would not be small in larger devices due to hard coding the size value. I was trying something like this

Container(
  child: Icon(
    Icons.beach_access,
    size: double.infinity,
  )
)
like image 239
Vishnu Avatar asked Apr 02 '20 21:04

Vishnu


People also ask

How do you change icon size on Flutter?

You can increase the size of Icon to a required value by assigning the size property with specific double value.

What is the default icon size in Flutter?

Icons occupy a square with width and height equal to size. Defaults to the current IconTheme size, if any. If there is no IconTheme, or it does not specify an explicit size, then it defaults to 24.0.


1 Answers

If you want the size of the icon to meet the ends of its Container parent, you can place it in a FittedBox

Container(
  child: FittedBox(
     child: Icon(
        Icons.beach_access,
          ),
        ),
      ),

You can change the fit property of the FittedBox to adjust some sizes and change alignment.

https://api.flutter.dev/flutter/widgets/FittedBox-class.html

like image 181
Texv Avatar answered Sep 22 '22 09:09

Texv