[英]Flutter: _TypeError (type 'Null' is not a subtype of type 'String')
[英]Error : _TypeError (type 'Null' is not a subtype of type 'String')
我需要在哪里解决这个问题? 它在readUserRideRequestInformation 中显示错误:“_TypeError(类型‘Null’不是类型‘String’的子类型)”
class PushNotificationSystem
{
FirebaseMessaging messaging = FirebaseMessaging.instance;
Future initializeCloudMessaging(BuildContext context) async
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage? remoteMessage)
{
//display ride request information - user information who request a ride
readUserRideRequestInformation(remoteMessage!.data["rideRequestId"], context);
});
}
function
import 'package:google_maps_flutter/google_maps_flutter.dart';
class UserRideRequestInformation
{
LatLng? originLatLng;
LatLng? destinationLatLng;
String? originAddress;
String? destinationAddress;
String? rideRequestId;
UserRideRequestInformation({
this.originLatLng,
this.destinationLatLng,
this.originAddress,
this.destinationAddress,
this.rideRequestId,
});
}
我如何解决它?
而不是使用 bang !
,你可以做一个null校验,或者使用字符串格式来传递null。
final rideRequestId = remoteMessage?.data["rideRequestId"];
if(rideRequestId != null){
readUserRideRequestInformation(rideRequestId, context);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.