7

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,
  )
)
Vishnubly
  • 539
  • 1
  • 8
  • 17
  • I want to set the size of Icon, with alignment property on Container I can only align the child – Vishnubly Apr 02 '20 at 21:22
  • You could try using a [SizedBox](https://api.flutter.dev/flutter/widgets/SizedBox-class.html) 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 Apr 02 '20 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 Apr 02 '20 at 22:13

1 Answers1

15

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

Texv
  • 1,225
  • 10
  • 14