Fork me on GitHub

Flutter - 弹出底部菜单Show Modal Bottom Sheet

在很多安卓App上,有很多底部弹出的菜单,这个在Flutter上同样可以实现。

先看一下效果

 

嗯,就是这样子的,当用户点击菜单区域以外的时候,菜单会自动关闭。

下面就看一下Dart语言实现

 

复制代码
floatingActionButton: new FloatingActionButton(
        onPressed: () {
          showModalBottomSheet(
              context: context,
              builder: (BuildContext context){
                return new Column(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    new ListTile(
                      leading: new Icon(Icons.photo_camera),
                      title: new Text("Camera"),
                      onTap: () async {
                        imageFile = await ImagePicker.pickImage(source: ImageSource.camera);
                        Navigator.pop(context);
                      },
                    ),
                    new ListTile(
                      leading: new Icon(Icons.photo_library),
                      title: new Text("Gallery"),
                      onTap: () async {
                        imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
                        Navigator.pop(context);
                      },
                    ),
                  ],
                );
              }
          );
        },
        foregroundColor: Colors.white,
        child: Text('点我'),
      ),
复制代码

 

可见,showModalBottomSheet只需要制定上下文context,在自己设计bulider即可。

posted @   猫叔Vincent  阅读(26630)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示