flutter - '_InternalLinkedHashMap' 不是类型 'Map 的子类型' 在类型转换中
问题描述
我有这个通用功能:
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);
}
但由于我从为我的 _dataClient 使用get_storage盒更改为配置单元盒,因此出现此错误:
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))`;
如果您使用它,您也可以删除通用功能。
推荐阅读
- javascript - 在Javascript中以非可变方式将字符串附加到数组
- magento - Magento 2 Cadence Dedup 文件名、目录名或卷标语法不正确
- c# - 如何解决aws Keyspaces中的“范围删除请求限制在单个范围内可以删除的项目数量”问题?
- javascript - 是否可以创建 Promise 类型的对象
> 在 JavaScript 中? - reactjs - 使用 useEffect 和 setState 更改状态后未重新呈现表数据
- javascript - 将 HTML 内容加载到 div 时,如何传递和检索一些数据?
- amazon-s3 - Outlook 阻止所有 Amazon S3 公共图像 URL
- java - 在 selenium 中一次处理 4 个窗口
- c# - .sprite 文件有标准格式吗?
- python - Python 错误仅适用于一组类似的事情?