【发布时间】:2020-06-28 23:19:38
【问题描述】:
我正在使用这个包https://pub.dev/packages/hive
我想保存和检索配置单元中的自定义对象列表。
我尝试过以下方法
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}');
但我遇到了错误
E/flutter (24061): [错误:flutter/shell/common/shell.cc(199)] Dart 错误:未处理的异常:E/flutter (24061): type 'List' is 不是类型转换 E/flutter 中“列表”类型的子类型 (24061): #0 BoxImpl.get (package:hive/src/box/box_impl.dart:43:26) E/flutter (24061): #1
_SourceToDestinationPageState.openStationBox
我已尝试检查 this 解决方案,但对如何解决此问题没有足够的了解。
以下是我正在使用的配置单元版本
- 蜂巢:^1.3.0
- hive_flutter:^0.3.0+1
- hive_generator: ^0.7.0
【问题讨论】:
-
你使用的是什么版本的飞镖?
标签: flutter dart flutter-dependencies flutter-hive