Hello I'm getting this error when I tried to run the code
lib/layout/home_layout.dart:54:36: Error: Method 'showBottomSheet' cannot be called on 'ScaffoldState?' because it is potentially null.
- 'ScaffoldState' is from 'package:flutter/src/material/scaffold.dart' ('/C:/src/flutter/packages/flutter/lib/src/material/scaffold.dart').
Try calling using ?. instead.
scaffoldKey.currentState.showBottomSheet(
^^^^^^^^^^^^^^^
I have a variable that I have defined:
var scaffoldKey = GlobalKey<ScaffoldState>();
Here I am trying to build a bottomsheet when clicking on the floatingactionbutton
floatingActionButton: FloatingActionButton(
onPressed: () {
scaffoldKey.currentState.showBottomSheet(
(context) => Container(
width: double.infinity,
height: 120.0,
color: Colors.red
),
);
},
child: const Icon(
Icons.add
),
),
Kindly, can someone tell me where I am going wrong?