如何在颤动中实现正确的导航栏?

问题描述 投票:1回答:2

颤振支架显示右侧导航栏,但我想没有正确的导航小部件。如何在颤动中使用支架实现正确的导航栏?

Flutter Scaffold Image

flutter
2个回答
1
投票

如果您尝试在应用中显示正确的栏/菜单或Drawer,无论是永久视图还是临时视图。我能够通过从AllignContainerColumn小部件构建我自己的自定义小部件,并使用setState根据用户交互显示或隐藏菜单栏来实现这一点,请参阅此简单示例。

enter image description here

我的自定义菜单小部件如下所示:

class RightNavigationBar extends StatefulWidget {
  @override
  _RightNavigationBarState createState() => new _RightNavigationBarState();
}

class _RightNavigationBarState extends State<RightNavigationBar> {
  @override
  Widget build(BuildContext context) {
    return new Align(
      alignment: FractionalOffset.centerRight,
      child: new Container(
        child: new Column(
          children: <Widget>[
            new Icon(Icons.navigate_next),
            new Icon(Icons.close),
            new Text ("More items..")
          ],
        ),
        color: Colors.blueGrey,
        height: 700.0,
        width: 200.0,
      ),
    );
  }
}

然后,当用户按下菜单icon时,我的自定义RightNavigationBar小部件的对象在setState中创建:

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var _myRightBar = null;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
          actions: [new IconButton(
              icon: new Icon (Icons.menu), onPressed: _showRightBar)
          ],
          title: new Text("Right Navigation Bar Example"),
        ),
        body: _myRightBar

    );
  }

  _showRightBar() {
    setState(() {
      _myRightBar == null
          ? _myRightBar = new RightNavigationBar()
          : _myRightBar = null;
    });
  }
}

0
投票

Scaffold现在有一个endDrawer属性,从右到左滑动。

希望这可以帮助某人。

© www.soinside.com 2019 - 2024. All rights reserved.