【问题标题】:deleteing hive flutter record using provider使用提供者删除蜂巢颤动记录
【发布时间】:2021-11-17 04:44:33
【问题描述】:

我是 Flutter 的新手,我正在尝试使用 Flutter、Hive 和提供程序创建待办事项应用程序。

当我尝试使用 deleteAt 方法删除记录时,不断收到以下异常。

[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: RangeError (index): Index out of range: no indices are valid: 3
E/flutter ( 4513): #0      RangeError.checkValidIndex (dart:core/errors.dart:303:7)
E/flutter ( 4513): #1      IndexableSkipList._getNodeAt (package:hive/src/util/indexable_skip_list.dart:196:16)
E/flutter ( 4513): #2      IndexableSkipList.getAt (package:hive/src/util/indexable_skip_list.dart:188:26)
E/flutter ( 4513): #3      Keystore.getAt (package:hive/src/box/keystore.dart:114:19)
E/flutter ( 4513): #4      BoxBaseImpl.deleteAt (package:hive/src/box/box_base_impl.dart:133:28)
E/flutter ( 4513): #5      TaskData.deleteTask (package:flutter_hive_toto/models/task_data.dart:38:14)
E/flutter ( 4513): <asynchronous suspension>
E/flutter ( 4513): 

通过使用以下代码,我尝试删除记录但没有成功。

  void deleteTask(int index)  async {
    var _taskBox =  await Hive.openBox<Task>('taskbox');
    print(index);
    _taskBox.deleteAt(index);
    getTasks();
    notifyListeners();
  }
}

【问题讨论】:

    标签: flutter flutter-provider flutter-hive


    【解决方案1】:

    您已打开 taskbox 并在 _taskBox 中保存了对打开框的引用。打开盒子数据后,您应该检索保存在_taskBox 中的数据,然后您可以访问它们以删除特定索引中的项目。尝试将对该框的引用保存在不同的变量中,然后将检索到的数据保存在_taskBox 中。请阅读Hive document,了解有关如何从蜂巢盒中读取数据的更多信息。

    【讨论】:

      猜你喜欢
      • 2021-01-29
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      • 2020-12-06
      • 1970-01-01
      • 2021-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多