2017-10-06 33 views

回答

0

Scaffold現在有一個endDrawer屬性,從右到左滑動。

希望這可能有助於某人。

1

如果你想顯示在您的應用程序的權利酒吧/菜單或Drawer,無論是具有永久視圖或臨時之一。我可以通過構建我自己的自定義小部件(從Allign,ContainerColumn小部件以及使用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; 
    }); 
    } 
}