首页 > 解决方案 > 单击左上角按钮单击(汉堡图标)时如何从侧面打开屏幕?

问题描述

单击图标时,我希望从左侧打开侧面菜单。

顶部标题

代码:

class _MovieScreenState extends State<MovieScreen> {


MovieBloc _bloc;
 final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

  @override
  void initState() {
    super.initState();
    _bloc = MovieBloc();

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      drawer: new Drawer(),
      appBar: AppBar(
        backgroundColor: Color(0xffFAFCF7), // status bar color
        brightness: Brightness.light,
        elevation: 0.0,
        leading: Container(
          margin: EdgeInsets.only(left: 17),
          child: RawMaterialButton(
            onPressed: _scaffoldKey.currentState.openDrawer(),
            child: new Icon(
              Icons.menu,
              // color: Colors.black,
              size: 25.0,
            ),
            shape: new CircleBorder(),
            elevation: 4.0,
            fillColor: Colors.white,
            padding: const EdgeInsets.all(5.0),
          ),
          ...

所以,onTap 我希望用全屏覆盖从左侧打开屏幕。另外,如果在主屏幕上从左向右滑动,是否可以打开侧屏幕。谢谢

标签: flutterflutter-layout

解决方案


是的,这是可能的,您正在寻找的小部件是Drawer

将参数传递drawer到您的 Scaffold 中,您将看到汉堡包图标

class LeftMenu extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
   return Container(child: 
      ListView(
        padding: EdgeInsets.zero,
        children:  // your widgets that you want to put inside
      )
   )
 }
}
Scaffold(
  drawer: Drawer(
    child: LeftMenu()
  )
);

现在可以使用汉堡菜单或从右向左滑动打开它。

您可以在官方教程中阅读更多信息:抽屉


推荐阅读