Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give a dynamic padding value to Padding widget?

Tags:

flutter

dart

My app will be used for different devices and different screen sizes and a well coded app should shown same at different screen sizes. Flutter has MediaQuery.of(context).size property. I wanna give a padding value to Padding widget like "padding: EdgeInsets.only(top: _height/3)" but it is not acceptable. Just static values has accept for padding. How to write a dynamic value to padding?

I tried to determine that "var _paddingTop = _height/3" at initState and still it isn't acceptable.

     Padding(
            padding: EdgeInsets.only(top: _height/4), 
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                // some widgets
              ],
            ),
          ),
like image 459
Can Karabag Avatar asked Jun 17 '19 07:06

Can Karabag


1 Answers

just remove the const

Padding(
            padding:  EdgeInsets.only(top: _height/4), 
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                // some widgets
              ],
            ),
          ),
like image 56
Sami Kanafani Avatar answered Sep 28 '22 06:09

Sami Kanafani