I trying make a button for open my drawer, but i can't, this my first time using flutter
my running ui
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();
},
),
The best way to do this is using GlobalKey.
Define a GlobalKey for ScaffoldState for your widget.
GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
Assign this key to the Scaffold.
Scaffold( key: scaffoldKey, ....)
FlatButton(onPressed: () { scaffoldKey.currentState.openDrawer(); })