简体   繁体   English

如何使 showModalBottomSheet 在 flutter 中响应?

[英]How to make showModalBottomSheet responsive in flutter?

I'am trying to show webView in a showModalBottomSheet, using inAppWebView plugin for webView. So when the webView state changes bottomSheet should adjust its height.我正在尝试在 showModalBottomSheet 中显示 webView,使用 webView 的 inAppWebView 插件。因此,当 webView state 更改 bottomSheet 时,应调整其高度。 Currently I just made a hotFix by giving scroll to bottomSheet.目前我只是通过滚动 bottomSheet 来制作一个 hotFix。

 return  return showModalBottomSheet(
      enableDrag: false,
      isDismissible: false,
      isScrollControlled: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.only(
          topRight: Radius.circular(20.r),
          topLeft: Radius.circular(20.r),
        ),
      ),
      context: context,
      builder: (context) => BottomSheet(),
    );
Widget build(BuildContext context) {
return Container(
      alignment: Alignment.center,
      height: MediaQuery.of(context).size.height - (kToolbarHeight * 2),
      decoration: BoxDecoration(
        color: lmWhite,
        borderRadius: BorderRadius.circular(20.r),
      ),
      clipBehavior: Clip.hardEdge,
      child: Stack(
        children: [
          InAppWebView(),
          Opacity(),
          ],
        ),
      );
   }

Default height for bottomSheet is half the screenSize bottomSheet 的默认高度是 screenSize 的一半

If you want your bottomSheet to Expand according to your content use below code如果您希望 bottomSheet 根据您的内容展开,请使用以下代码

showModalBottomSheet<dynamic>(
isScrollControlled: true,
context: context,
builder: (BuildContext bc) {
  return Wrap(
      children: <Widget>[...]
  )
 }
)

This will automatically expand the bottomSheet according to content inside.这样会根据里面的内容自动展开bottomSheet。

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

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