Flutter Hive retrieve box elements and obtain key when using ListView.builder

Viewed 1656

Using Hive, I can Hive.openBox('boxName') to then pass into a ListView.builder and cast the entry to a Model to get the required information for my view like this:

ListView.builder(
    itemCount: list?.length,
    itemBuilder: (context, index) {
        final location = list.getAt(index) as Location; //casting to a Model
        
        //Widget code here to use location.ModelProperty, etc.
    },
 )

This works great, but I really need to be able to get the box's entry key record. All of my records are being saved with a key like await box.put(nowSinceEpoch.toString(), data). How would I refactor this to still be able to pass in the box itself, and not have to do additional mapping or manipulation of the data being passed into the ListView.builder?

0 Answers
Related