Deven Valisten
Deven Valisten

Reputation: 67

Flutter Hive, How to filter hive box to listenable

I want to show data from hive, but i want to filter spesific box only to pass to ValueListenableBuilder, using this :

  // Read all note (working properly)
  static ValueListenable<Box<NoteModel>> readNote() {
    return noteBox.listenable();
  }

that code show all of available box, i have query the box but i don't know how to add to listenable(), heres the query :

var filtered =  noteBox.values.where((note) => note.isArchived == false).toList();

Upvotes: 0

Views: 1748

Answers (1)

R3HP
R3HP

Reputation: 510

what you should do is to listen first and then sort and filter on values listened

ValueListenableBuilder<Box<YOUR_BOX_MODEL>>(
valueListenable: box.listenable(),
builder: (context,value,child){
    final sortedValues = value.values.toList()..sort((firstValue,secondValue) => firstValue.compareTo(secondValue));

    final filteredValues = value.values.where(() => YOUR_CONDITION_HERE);
)

Upvotes: 1

Related Questions