未处理的异常:类型 'Future<dynamic>' 不是类型转换中类型 'PersistentBottomSheetController<dynamic>' 的子类



我现在正在将代码转换为空安全。所以现在我已经对我的代码做了这些更改。最初的返回类型是void,然后我改成了Future?但我确实得到了这个CCD_ 1上的错误。我还可以做些什么来修复它。

Future<dynamic>? _showBottomSheet(
context, MapDashboardDetails details) async {

//_showPersBottomSheetCallBack = null;
showingBottomSheet = true;
_controller = _scaffoldKey.currentState!
.showBottomSheet((context) {
return VBottomSheet(
details: details,            
onCloseTapped: () {
Navigator.of(context).pop();
},
);
})
.closed
.whenComplete(() {
if (mounted) {
showingBottomSheet = false;
_showPersBottomSheetCallBack = _showBottomSheet;
}
}) as PersistentBottomSheetController;
return null;
}

以下是我如何调用它。即使这是在void之前,然后我添加了Future和async,但仍然无法解决它。

Future<dynamic> _onMarkerTapped(MapDashboardDetails details) async {

if (showingBottomSheet) {
Navigator.of(context).pop();
showingBottomSheet = false;
}   
_showBottomSheet(context, details);
}
_scaffoldKey.currentState!
.showBottomSheet((context) {
...
})
.closed
.whenComplete(() {
...
});

这将返回Future而不是PersistentBottomSheetController。因此,你的演员阵容(=as…(试图塑造一个未来<无效>而事实并非如此。所以解决方案是只返回whenComplete返回的未来:

return _scaffoldKey.currentState!
.showBottomSheet((context) {
...
})
.closed
.whenComplete(() {
...
});

相关内容

最新更新