我试图做一个打开抽屉的按钮,但我不能,这是我第一次使用颤动
我正在运行的用户界面
return Scaffold(
drawer: Drawer(),
body: Column(
children: <Widget>[
ClipPath(
clipper: MyClipper(),
child: Container(
height: 350,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
Color(0xFF3383CD),
Color(0xFF11429F),
]),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 12),
IconButton(
icon: const Icon(
Icons.add, size: 18,
color: Colors.white,
),
onPressed: () {
Scaffold.of(context).openDrawer();
},
),
答案 0 :(得分:0)
做到这一点的最好方法是使用GlobalKey。
为窗口小部件定义ScaffoldState的GlobalKey。
GlobalKey<ScaffoldState> scaffolKey = GlobalKey<ScaffoldState>();
将此密钥分配给脚手架。
Scaffold( key: scaffoldKey, ....)
FlatButton(onPressed: () { scaffoldKey.currentState.openDrawer(); })