简体   繁体   English

如何在 Flutter 的底部填充中使用 MediaQuery

[英]How to use MediaQuery in bottom padding in Flutter

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),

Remove the const keyword will fix the error...as getting a value from MediaQuery.of(context) you can't use a constant keyword.删除 const 关键字将修复错误...因为从 MediaQuery.of(context) 获取值您不能使用常量关键字。

eg例如

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

You need to remove the const keyword.您需要删除 const 关键字。 Because, MediaQuery.of(context).viewInsets.bottom + 10) is not static.因为, MediaQuery.of(context).viewInsets.bottom + 10)不是 static。 It is a dynamic value.这是一个动态值。 A dynamic value cannot be const.动态值不能是 const。

you need to write:你需要写:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM