Home > Mobile >  How to use MediaQuery in bottom padding in Flutter
How to use MediaQuery in bottom padding in Flutter

Time:12-07

I am trying to use media query in bottom padding so that the soft keyboard won’t cover the form on the modal bottomsheet but I am getting an invalid constant value error and a red line from the media Query. This is what I typed:

padding: const EdgeInsets.only( top: 10, left: 10, right: 10, bottom: MediaQuery.of(context).viewInsets.bottom 10),

CodePudding user response:

Remove the const keyword will fix the error...as getting a value from MediaQuery.of(context) you can't use a constant keyword.

e.g.

 padding: EdgeInsets.only( top: 10, left: 10, right: 10, bottom: MediaQuery.of(context).viewInsets.bottom   10),

CodePudding user response:

You need to remove the const keyword. Because, MediaQuery.of(context).viewInsets.bottom 10) is not static. It is a dynamic value. A dynamic value cannot be const.

you need to write:

padding: EdgeInsets.only( top: 10, left: 10, right: 10, bottom: MediaQuery.of(context).viewInsets.bottom   10)
  • Related