我现在正在将我的代码转换为空安全。所以现在我已经对我的代码做了这些更改。最初的返回类型是void,然后我改成了Future?但是我确实明白这个错误
Unhandled Exception: type 'Future<dynamic>' is not a subtype of type 'PersistentBottomSheetController<dynamic>' in type cast
。我还可以做些什么修改来修复它。
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);
}