Flutter Hive 模型抛出索引超出范围:没有有效索引:填充 HiveList 时出现 0 错误

问题描述

我正在尝试在我的 Flutter 应用程序中填充一个 Hive 框。我用一些任务对象填充它,然后每个任务都有一个线索对象的 HiveList

  Box<Quest> quests = await initQuests();
  List<Clue> clues = await initClues();

  for (var i = 0; i < quests.length; i++) {
    Quest cQuest = quests.getAt(i);
    Iterable<Clue> questClues = clues.where((cclue) => cclue.associatedQuest == cQuest.id);
    Box<Clue> questCluesBox = await Hive.openBox<Clue>('quest_${cQuest.id}_clues');
    questCluesBox.addAll(questClues);

    quests.getAt(i).clues = HiveList(questCluesBox);
    cQuest.save();
  }

当我运行代码时出现以下错误

[ERROR:Flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: RangeError (index): Index out of range: no indices are valid: 0

我正在分配一个变量,而不是尝试访问数组中的元素,所以我不知道错误意味着什么。

有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)