flutter showModalBottomSheet 底部弹出 类似Android PopupWindow

构造方法

Future<T> showModalBottomSheet<T>({
  @required BuildContext context,
  @required WidgetBuilder builder,
  Color backgroundColor,
  double elevation,
  ShapeBorder shape, //弹窗shape可以设置圆角
  Clip clipBehavior,
  Color barrierColor,
  bool isScrollControlled = false,
  bool useRootNavigator = false,
  bool isDismissible = true,//能否点击消失
  bool enableDrag = true,//能否拖拽消失
})

使用

  _showPopWindow() {
    showModalBottomSheet<String>(
        context: context,
        isDismissible: false,//设置点击弹窗外边是否关闭页面
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(topLeft: Radius.circular(20),topRight: Radius.circular(20)),
        ),
        builder: (BuildContext context) {
          return Container(
            padding: EdgeInsets.symmetric(vertical: ScreenUtil().setHeight(30)),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                ListTile(
                  leading: new Icon(Icons.photo_camera),
                  title: new Text("Camera"),
                  onTap: () async {
                    Navigator.pop(context, 'camera');
                  },
                ),
                ListTile(
                  leading: new Icon(Icons.photo_library),
                  title: new Text("Gallery"),
                  onTap: () async {
                    Navigator.pop(context, 'Gallery');
                  },
                ),
              ],
            ),
          );
        }).then((value) => print('showModalBottomSheet $value'));
  }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容