【发布时间】:2021-04-03 07:00:04
【问题描述】:
我有这个通用函数:
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 框更改为 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 必须将数据存储为不同的格式,这可能是由于加密的原因,但我该如何解决这个问题并消除此错误?
【问题讨论】: