Search code examples
flutterflutter-layoutflutter-animation

Flutter, is it bad habit to use MediaQuery for sizing every widgets?


I almost use like

double number = 0.2;
someWidgetSize : MediaQuery.of(context).size."width or height" * number 

for every widgets

but suddenly I thought that it is too easy to make widgets for all device screen sizes

so I`m just curious is it bad habits?(it may have side effects or something)

thanks


Solution

  • No. There is no side effects about this.

    We all do this when it is important to have a dynamic widget size. Just be aware that this uses the device size. If you want to use the parent widget's dize use LayoutBuilder widget that gives you the constraints of the parent wiget.