SlideDrawer,toggle()方法在Null上被调用



我是,在flutter中使用SlideDrawer((,但在调用它时遇到错误,Toggle((或open((方法在null上被调用。。

代码我在哪里打电话我是,在flutter中使用SlideDrawer((,但在调用它时我收到了一个错误,Toggle((或open((方法在null上被调用。。

代码我在哪里呼叫

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Irr Alert"),
backgroundColor: Colors.orange,
leading: IconButton(
icon: Icon(Icons.menu),
onPressed: () => SlideDrawer.of(context).toggle(),
),
),
body: Container(
height: MediaQuery.of(context).size.height,
child: Center(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => AddDevice()));
},
child: Column(
children: [
Container(
child: Image.network(
addDevice,
height: 150,
width: 150,
),
),
SizedBox(
height: 10,
),
Text(
"Add Device",
style: TextStyle(fontSize: 25),
),
],
),
),
SizedBox(
height: 20,
),
GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => ShowDevices()));
},
child: Column(
children: [
Image.network(
showDevice,
height: 150,
width: 150,
),
SizedBox(
height: 10,
),
Text(
"Show Device",
style: TextStyle(fontSize: 25),
),
],
),
),
SizedBox(
height: 20,
),
GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => CropDetails()));
},
child: ClipRRect(
borderRadius: BorderRadius.circular(70),
child: Image.network(
cropSeeds,
height: 150,
width: 150,
fit: BoxFit.cover,
),
),
),
SizedBox(
height: 10,
),
Text(
"Crop Details",
style: TextStyle(fontSize: 25),
),
SizedBox(
height: 10,
),
],
),
),
),
),
);
}

您需要将Scaffold密钥传递给滑动抽屉,还需要将其分配给您的主Scaffold

final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();

@override
Widget build(BuildContext context) {

return Scaffold(
key: scaffoldKey
drawer: Drawer(
key: scaffoldKey,
),
body: Container(

),
);
}

最新更新