9

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,
  )
)
3
  • I want to set the size of Icon, with alignment property on Container I can only align the child
    – Vishnubly
    Commented Apr 2, 2020 at 21:22
  • You could try using a SizedBox around the Icon provided you have set the dimensions of the Container surrounding the Icon correctly. I would recommend using MediaQuery to get the dimensions of the screen and set the height/width of the container appropriately for the screensize.
    – Jwildsmith
    Commented Apr 2, 2020 at 21:27
  • The container filling the whole screen or inherit size from another widget? If from another widget then add that widget code in your question
    – LonelyWolf
    Commented Apr 2, 2020 at 22:13

1 Answer 1

17

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

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.