简体   繁体   English

Flutter Hive - 未处理的异常:输入“列表”<dynamic> &#39; 不是 &#39;List 类型的子类型<SourceStations> &#39; 在类型转换中

[英]Flutter Hive - Unhandled exception: type 'List<dynamic>' is not a subtype of type 'List<SourceStations>' in type cast

I am using this package https://pub.dev/packages/hive我正在使用这个包https://pub.dev/packages/hive

I want to save and retrieve a list of custom objects in the hive.我想保存和检索配置单元中的自定义对象列表。

I have tried to below approach我试过下面的方法

await Hive.openBox<List<SourceStations>>(stationBox); //Open box
Box<List<SourceStations>> sourceStationsBox = Hive.box(stationBox); 
sourceStationsBox.put(stationBox, listSourceStation); //Saving list of custom object as listSourceStation
//Should probably give lenght of list of custom object
logger.d('station box list length is ${sourceStationsBox.get(stationBox).length}'); 

But I am getting below error但我得到以下错误

E/flutter (24061): [ERROR:flutter/shell/common/shell.cc(199)] Dart Error: Unhandled exception: E/flutter (24061): type 'List' is not a subtype of type 'List' in type cast E/flutter (24061): #0 BoxImpl.get (package:hive/src/box/box_impl.dart:43:26) E/flutter (24061): #1 E/flutter (24061): [ERROR:flutter/shell/common/shell.cc(199)] Dart Error: Unhandled exception: E/flutter (24061): type 'List' is not a subtype of type 'List' in类型转换 E/flutter (24061): #0 BoxImpl.get (package:hive/src/box/box_impl.dart:43:26) E/flutter (24061): #1
_SourceToDestinationPageState.openStationBox _SourceToDestinationPageState.openStationBox

I have tried checking this solution but not getting enough idea how to fix this.我试过检查这个解决方案,但没有足够的想法如何解决这个问题。

Following are the hive version I am using以下是我正在使用的配置单元版本

  • hive: ^1.3.0蜂巢:^1.3.0
  • hive_flutter: ^0.3.0+1 hive_flutter:^0.3.0+1
  • hive_generator: ^0.7.0 hive_generator:^0.7.0

"Generic type parameters like Box<List> are unsupported due to Dart limitations." “由于 Dart 的限制,不支持像Box<List>这样的通用类型参数。” This is mentioned in the author documentation: https://docs.hivedb.dev/#/basics/boxes at the bottom of the page.这在作者文档中提到: https : //docs.hivedb.dev/#/basics/boxes在页面底部。

If you are not using a ValueListenableBuilder , you can do it like this:如果您没有使用ValueListenableBuilder ,您可以这样做:

await Hive.openBox<List<SourceStations>>(stationBox); //Open box
Box<List<SourceStations>> sourceStationsBox = Hive.box(stationBox); 
sourceStationsBox.put(key, listSourceStation); // key is a string
logger.d('station box list length is ${sourceStationsBox.get(key).length}'); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter:未处理的异常:输入“未来” <list<dynamic> &gt;' 不是类型“列表”的子类型<dynamic> ' 在类型转换中</dynamic></list<dynamic> - Flutter: Unhandled Exception: type 'Future<List<dynamic>>' is not a subtype of type 'List<dynamic>' in type cast Flutter:未处理的异常:键入“列表”<dynamic> ' 不是类型 'List 的子类型<double> ' 在类型转换中</double></dynamic> - Flutter : Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<double>' in type cast 未处理的异常:“Null”类型不是“List”类型的子类型<dynamic> ' 在类型转换中</dynamic> - Unhandled Exception: type 'Null' is not a subtype of type 'List<dynamic>' in type cast 未处理的异常:类型 '_InternalLinkedHashMap<string, dynamic> ' 不是类型 'List 的子类型<dynamic> ' 在请求中的类型转换 flutter</dynamic></string,> - Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>' in type cast in request flutter Flutter 未处理的异常:“Null”类型不是“List”类型的子类型<dynamic> ' 在类型转换中</dynamic> - Flutter Unhandled Exception: type 'Null' is not a subtype of type 'List<dynamic>' in type cast Flutter '未处理的异常:类型'列表<dynamic> ' 不是类型 'List 的子类型<class> '</class></dynamic> - Flutter 'Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<class>' Flutter:未处理的异常:键入“列表”<dynamic> ' 不是类型 'List 的子类型<string> '</string></dynamic> - Flutter:Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<String>' 未处理的异常:键入“列表”<dynamic> ' 不是 'SubJsonModel' 类型的子类型 - flutter</dynamic> - Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'SubJsonModel' - flutter Dart 未处理的异常:键入“列表”<dynamic> ' 不是类型 'Family' 的子类型,- Flutter</dynamic> - Dart Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'Family', - Flutter 未处理的异常:键入“列表”<String> &#39; 不是类型转换中类型 &#39;String&#39; 的子类型 - Unhandled Exception: type 'List<String>' is not a subtype of type 'String' in type cast
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM