废话一句:通过设置 GlobalKey 来让 Scaffold 容器获取到其内部的 Drawer 组件,进而控制它的开闭,这样,我们就已经可以通过点击自定义的用户头像来开启左边侧滑栏。
查看资料全是用的futter自身带的按钮触发侧滑,下面是自定义导航栏按钮实现侧滑。
上代码
class MainPageState extends State<MainPage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey();
Color themeColor = ThemeUtils.currentColorTheme;
var images;
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
theme: ThemeData(
primaryColor:themeColor
),
home: Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Text("xxx",
style: TextStyle(
color: Colors.black,fontSize: 18.0
),
),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: new Container(
padding: EdgeInsets.all(1),
child: Image.asset('images/search.png'),
),
onPressed: null,
),
IconButton(
icon: new Container(
padding: EdgeInsets.all(1),
child: Image.asset('images/message.png'),
),
onPressed: null,
),
],
leading: new IconButton(
icon: new Container(
padding: EdgeInsets.all(0),
child: Image.asset('images/Shape.png'),
),
onPressed: () {
_scaffoldKey.currentState.openDrawer();
},
),
),
drawer: MyDrawer()
),
);
}
}