Question
So let's say I have a list of books. Deleting book at nth index using deleteAtis not deleting it and shifting (n+1)th element to its place, rather it is making it null. i.e. the element at nth is now null.
How to perform deleteAtperfectly?
BTW I have used delete outside of the ValueListenableBuilder.
Code sample
ValueListenableBuilder(
valueListenable: Hive.box('books').listenable(),
builder: (context, box, _) {
if (box.values.length == 0)
return Center(
child: Text("No books"),
);
return ListView.builder(
primary: true,
padding: EdgeInsets.only(bottom: 95),
itemCount: box.values.length,
itemBuilder: (context, int index) {
Book book = box.get(index);
return Padding(
padding:
const EdgeInsets.only(bottom: kMasterPadding),
child: BookItem(
title: book.title,
author: book.authorName,
),
);
},
);
},
),
code used for deletion
() async {
await Hive.box("books").deleteAt(Hive.box("books").length - 2);
//deleted at last 2nd because deleting at the end was working perfectly
},
Version
I tried to reproduce the issue, but it works correctly.
| Code | Result |
|---|---|
|
|
Exactly. It is working but just not in my project. I can not find what's wrong.
@Illusion47586 could you try Book book = box.getAt(index); instead of box.get? It should work now.
And that just worked! Thank you so much.