【问题标题】:Error : _TypeError (type 'Null' is not a subtype of type 'String')错误:_TypeError(类型 \'Null\' 不是类型 \'String\' 的子类型)
【发布时间】:2023-01-12 07:13:38
【问题描述】:

我需要在哪里解决这个问题?它显示错误:“_TypeError(类型‘Null’不是类型‘String’的子类型)”在 readUserRideRequestInformation 中

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);
    });
  }

功能

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,
  });
}

enter image description here

我如何解决它?

【问题讨论】:

    标签: flutter dart dart-null-safety


    【解决方案1】:

    除了使用 bang !,您还可以进行 null 检查,或者使用字符串格式传递 null。

    if(remoteMessage!=null){
        readUserRideRequestInformation(remoteMessage.data["rideRequestId"], context);
      }
    

    【讨论】:

    猜你喜欢
    • 2022-11-14
    • 2021-12-14
    • 2021-02-05
    • 2021-01-25
    • 1970-01-01
    • 1970-01-01
    • 2023-02-24
    • 2022-07-22
    • 2021-03-29
    相关资源
    最近更新 更多