无法交换配置单元数据库中记录的位置,出现类似“未处理的异常”的错误:HiveError:HiveObject的同一示例不能使用两个不同的键(“5”和“10”)存储。
密码:
Box<CounterDetails> box = await Hive.openBox<CounterDetails>(kHiveBoxName);
if (oldIndex < newIndex) {
newIndex -= 1;
}
// this is required, before you modified your box;
final oldItem = box.getAt(oldIndex);
final newItem = box.getAt(newIndex);
// here you just swap this box item, oldIndex <> newIndex
box.putAt(oldIndex, newItem!);
box.putAt(newIndex, oldItem!);
1条答案
按热度按时间qxsslcnc1#
对于错误,你可以在
CounterDetails
上创建copyWith
方法,它将返回新的示例。或者创建复制字段的新示例。然后把这个新对象。copyWith方法将类似于
把这些放在一起就像