hive box get method returns dynamic and here i cant understand how to convert it to our required data type
here is how i have written data to box
void saveData() {
myBox.put('myInt',89);
myBox.put('myString', 'Welcome');
myBox.put('myMap', {'Name':'Vicky','Age':30});
myBox.put('myList1', [10,20,30,40,50]);
myBox.put('myList2', ['A','B','C','D','E']);
}
and now i want to read from hive box and store into controller’s variables when fetchData method call..
class DataController extends GetxController {
static DataController get instance => Get.find();
RxBool isLoading = false.obs;
Rx<int> myInt=0.obs;
Rx<String> myString=''.obs;
RxMap<String,dynamic> map=<String,dynamic>{}.obs;
RxList<int> myList1=<int>[].obs;
RxList<String> myList2=<String>[].obs;
Box myBox = Hive.box('database');
@override
void onInit() {
// TODO: implement onInit
super.onInit();
fetchData();
}
void fetchData() async {
try {
myInt.value=myBox.get('myInt') as int;
myString.value=myBox.get('myString') as String;
map.value=myBox.get('myMap') as Map<String,dynamic>;
myList1.value=myBox.get('myList1') as List<int>;
myList2.value=myBox.get('myList2') as List<String>;
} catch (e) {
print("Error is "+e.toString());
isLoading.value = false;
}
}
}