I am creating a simple app for transaction using hive..
i am success to add and fetch all transaction and assign to controller’s list but how to update local storage of hive, bcz i am ussing add method to add data in box, and add does generate id its own way..so how to get it to update specific key’s value
class TransactionController extends GetxController {
static TransactionController get instance=>Get.find();
RxList<TransactionModel> _allTransactions = <TransactionModel>[].obs;
List<TransactionModel> get getAllTransactions=>_allTransactions;
RxBool isLoading=false.obs;
Box<TransactionModel> transactionbox = Hive.box('MyBox');
@override
void onInit() {
// TODO: implement onInit
super.onInit();
fetchData();
}
void fetchData() async {
try{
isLoading.value=true;
final data=transactionbox.values.toList();
if(data!=null)
{
_allTransactions.assignAll(data);
}
isLoading.value=false;
}catch(e){
print('E R R O R'+e.toString());
isLoading.value=false;
}
}
void addTransaction(TransactionModel transactionModel)
{
_allTransactions.add(transactionModel);
_allTransactions.refresh();
transactionbox.add(transactionModel);
}
void update(TransactionModel transactionModel){
transactionbox.put(key,transactionModel);
//how to get key of this transactonModel bcz add method generate its own..
}
}