flutter在使用showModalBottomSheet時,當(dāng)彈層上有Textfield時,會出現(xiàn)鍵盤遮擋問題,解決辦法如下:
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;