Flutter 悬浮弹出效果

最近在 Flutter 的使用中需要做一个悬浮弹窗的效果。通过查阅资料了解 Overlay 可以做出悬浮框的效果,但没有弹出效果,不符合我的预期。后来发现其实并不一定要真的悬浮,通过 showModalBouttonSheet方法和 Stack组件,可以模拟出这样的效果。

  Future _createSelectViewWithContext() async {
    //屏幕宽高
    RenderBox renderBox = context.findRenderObject();
    var screenSize = renderBox.size;
    final option = await showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return StatefulBuilder(builder: (context, state) {
            return Stack(
                alignment: AlignmentDirectional.topCenter,
                children: <Widget>[
                  Container(
                    color: Colors.black54,
                    height: screenSize.height * 0.37,
                    width: double.infinity,
                  ),
                  Container(
                    height: screenSize.height * 0.35,
                    width: screenSize.width * 0.95,
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(20.0))),
                    child: Column(
                      children: <Widget>[
                        Text(
                          'This is a title',
                          style: TextStyle(color: Colors.grey, fontSize: 25),
                        ),
                        Divider(),
                        Expanded(
                            child: ListView(
                          children: <Widget>[
                            ListTile(
                              leading: Icon(Icons.home),
                              title: Text('home'),
                              trailing: RaisedButton(
                                  onPressed: () {},
                                  color: Colors.blue,
                                  shape: RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(20)),
                                  child: Text('botton')),
                            ),
                            ListTile(
                              leading: Icon(Icons.hotel),
                              title: Text('hotel'),
                              trailing: RaisedButton(
                                  onPressed: () {},
                                  color: Colors.blue,
                                  shape: RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(20)),
                                  child: Text('botton')),
                            ),
                          ],
                        ))
                      ],
                    ),
                  )
                ]);
          });
        });
  }

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值