flutter 使用showModalBottomSheet时Textfield键盘遮挡问题

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;
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容