错误:参数类型“Uint8List?”不能分配给参数类型 'Iterable<int>

时间:2021-05-21 07:45:18

标签: flutter dart dart-null-safety

当我转换为 Null-safe 时,我就是这个,并且我不断收到此错误

error

这是我的代码

try {
      final AuthorizationResult appleResult =
          await TheAppleSignIn.performRequests([
        AppleIdRequest(requestedScopes: [Scope?.email, Scope?.fullName])
      ]);
      if (appleResult.error != null) {
        // handle errors from Apple here
      }

      final AuthCredential credential = OAuthProvider('apple.com').credential(
        accessToken:
            String.fromCharCodes(appleResult.credential!.authorizationCode),//here the error coming out.... i have also try Uint8List.fromList but still showing the error
        idToken: String.fromCharCodes(appleResult.credential!.identityToken),//here the error coming out.... i have also try Uint8List.fromList but still showing the error
      );
      final firebaseResult = await auth.signInWithCredential(credential);
      users = firebaseResult.user;
      if (users == null) {
        return false;
      }
      return true;
    } catch (error) {
      print(error);
      return false;
    }

我也试过

Uint8List.from()

1 个答案:

答案 0 :(得分:0)

问题:

您的 Uint8List? 是可空的,而 Iterable<int> 是不可空的,因此您不能将可空分配给不可空。

解决方案:

  1. 如果 Unit8List? 可以是 null,请提供一个默认值。

    Iterable<int> iterable = yourUint8List ?? []; 
    
  2. 如果 Uint8List? 不能为 null,请使用 bang 运算符。

    Iterable<int> iterable = yourUint8List!;