Vishnubly
Vishnubly

Reputation: 729

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

Upvotes: 9

Views: 9088

Answers (1)

Texv
Texv

Reputation: 1869

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

Upvotes: 17

Related Questions