Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add padding using Media query in Flutter?

Tags:

flutter

I need to add padding according to the screen size of the user but on adding this code it is showing invalid constant value, can somebody please suggest me the alternative or a better solution.

padding: const EdgeInsets.all(MediaQuery.of(context).size.width/10),
like image 851
Rudraksh Dixit Avatar asked May 14 '19 04:05

Rudraksh Dixit


2 Answers

Remove const and you should be good to go.

padding: EdgeInsets.all(MediaQuery.of(context).size.width/10),
like image 139
CopsOnRoad Avatar answered Sep 27 '22 19:09

CopsOnRoad


padding: const EdgeInsets.symmetric(horizontal: MediaQuery.of(context).size.width/10), // error

var width = MediaQuery.of(context).size.width;//can be used globally and similarly with height to.

padding: EdgeInsets.symmetric(horizontal:width /10,), //after removing const 
like image 43
Dev Bathani Avatar answered Sep 27 '22 19:09

Dev Bathani