flutter在使用showModalBottomSheet时,当弹层上有Textfield时,会出现键盘遮挡问题,解决办法如下:
showModalBottomSheet(
backgroundColor: Colors.white,
isScrollControlled: true,
context: context,
builder: (ctx) {
return Container(
height: 350,
margin: EdgeInsets.only(bottom:MediaQuery.of(context).viewInsets.bottom),//主要是这句
);
});
有兴趣的可以看下MediaQuery.of(context).viewInsets的解释
/// The parts of the display that are completely obscured by system UI,
/// typically by the device's keyboard.
///
/// When a mobile device's keyboard is visible `viewInsets.bottom`
/// corresponds to the top of the keyboard.
///
/// This value is independent of the [padding] and [viewPadding]. viewPadding
/// is measured from the edges of the [MediaQuery] widget's bounds. Padding is
/// calculated based on the viewPadding and viewInsets. The bounds of the top
/// level MediaQuery created by [WidgetsApp] are the same as the window
/// (often the mobile device screen) that contains the app.
///
/// See also:
///
/// * [ui.window], which provides some additional detail about this property
/// and how it relates to [padding] and [viewPadding].
final EdgeInsets viewInsets;