如何在listview中过滤hive数据



我使用ValueListenableBuilder来获取存储在hive box中的NoteData的ListView。

SizedBox(
width: 900,
child: ValueListenableBuilder<Box<NoteData>>(
valueListenable: Boxes.getNotes().listenable(),
builder: (context, box, _) {
final notes = box.values.toList().cast<NoteData>();
// var _filteredNotes
return ListView.builder(
itemCount: notes.length,
itemBuilder: (context, index) {
return NoteView(note: notes[index]);
});
}),
),

现在我想用TextField的onChanged回调来过滤显示的结果。我怎么做呢?

SizedBox(
height: 60,
width: 242,
child: TextField(
onChanged: ((value) {}), // (value) => _runFilter(value),
decoration: const InputDecoration(
labelText: 'Notiz suchen',
labelStyle: TextStyle(
color: Colors.white,
),
suffixIcon: Icon(
Icons.search,
color: Colors.white,
),
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white))),
),
)

我找到了一些关于如何过滤列表视图的教程,但我不知道如何在我的项目中实现它,而使用蜂巢盒。

您需要对从hive中检索到的值执行一些条件反射。更多信息与示例:更多信息。然后更新/重新绘制你的ListView