'showBottomSheet' can't be unconditionally invoked because the receiver can be '

743 阅读1分钟

Flutter在使用GlobalKey().currentState.showBottomSheet实现BottomSheet:底部滑动窗口 出现如下报错

The method 'showBottomSheet' can't be unconditionally invoked because the receiver can be 'null'.\
Try making the call conditional (using '?.') or adding a null check to the target ('!').

image.png

解决办法:向目标中添加一个空检查('!')
.currentState.showBottomSheet

image.png