flutter - 类型转换中的“_InternalLinkedHashMap <dynamic,dynamic >' is not a subtype of type ' Map <String,dynamic>”

标签 flutter dart

我有这个通用函数:

  ValueType get<ValueType>(String keyToRead) {
    try {
      return _dataClient.get(keyToRead) as ValueType;
    } on SocketException catch (error) {...

我这样调用它:

  @override
  Map<String, dynamic> getUserRegistration() {
    return dataClient.get<Map<String, dynamic>>(UserRegistrationFieldKeys.self);
  }

但是自从我改变使用 get_storage我的 _dataClient 框到 hive框,我收到此错误:

The following ProviderException was thrown building LoggedOutPageView(dirty, dependencies: [UncontrolledProviderScope], state: _ConsumerState#6c90b):
An exception was thrown while building AutoDisposeProvider<RegisterViewModel>#00006().

Thrown exception:
type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>' in type cast

Stack trace:
#0      LocalDataClient.get
package:vepo/…/data_clients/local_data_client.dart:51
#1      UserRegistrationLocalDataSource.getUserRegistration
package:vepo/…/user_registration/user_registration_local_data_source.dart:22
#2      UserRegistrationRepository.getUserRegistration
package:vepo/…/user-registration/user_registration_repository.dart:31

Hive 必须将数据存储为不同的格式,这可能是由于加密的原因,但我该如何解释并消除此错误?

最佳答案

尝试使用

Map<String, dynamic>.from(dataClient.get(UserRegistrationFieldKeys.self))`;

如果您使用它,您也可以删除通用函数。

关于flutter - 类型转换中的“_InternalLinkedHashMap <dynamic,dynamic >' is not a subtype of type ' Map <String,dynamic>”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65444862/

相关文章:

redux - flutter redux 中有没有一种方法可以在分派(dispatch)另一个 Action 时分派(dispatch)一个 Action ?

flutter - 为什么我的堆栈剪裁图像的右侧?

firebase - Flutter Firebase Cloud Messaging onMessage 被触发两次

dart - Polymer + dart2js:输出太大

node.js - Flutter Socket io 几秒钟后断开连接

dart - 如何在同一设备上为不同项目使用两个版本的 Flutter?

dart - 为什么 Dart 有编译时常量?

http - 如何从http POST请求结果列表中显示listview构建器上的数据

dart - flutter 如何让循环进度指示器工作

Flutter 地理定位器插件 Geolocator().placemarkFromAddress() 和 Geolocator().placemarkFromCoordinates() 不起作用