From my Hive box I have created a list of Widgets of a certain specified type.
Hive.box<Job>('jobBox').values.where((element) => element.jobType == selectedType).toList().map(
(jobList)
I have create a favorites button which generates from the initial stored values in the Hive box, so if it is already set to true or false.
GestureDetector(
child: Icon(
jobList.fav
? Icons.favorite
: Icons.favorite_border,
color: jobList.fav ? Colors.red.shade200 : Colors.grey,
),
onTap: () {
if (jobList.fav == true){
setState(() {
jobList.fav = false;
// Hive.box<Job>('jobBox').putAt(); //This is where I am having my problem
print(jobList.jobID );
print(jobList.fav );
});
}
else{
setState(() {
jobList.fav = true;
// Hive.box<Job>('jobBox').putAt(); //This is where I am having my problem
print(jobList.jobID );
print(jobList.fav );
});
}
}
// )
),
The setState updates the favorite icon and changes the value, but on closing and reopening the app it restores the original default values in the Hive box. Which makes sense as I haven't updated the Hive box.
But what is the correct way to update this fav value in the Hive box? I have tried putAt using the jobID for the index, which I assume gets me to the correct record. But then how to I just change the fav field from true to false or from false to true?
Do I have to overwrite all the field values in the box at this index?
Hive.box<Job>('jobBox').putAt(jobList.jobID, ???);