DiscoverModule/lib/hive_fun.dart

243 lines
6.9 KiB
Dart

import 'package:hive_flutter/hive_flutter.dart';
class HiveFunctions {
// String userHiveBox="User Box";
// Box which will use to store the things
static final _contactbox = Hive.box("mycontact");
static var box1 = Hive.box('checkvalue');
static final apihcpdata = Hive.box("hcpdata");
static createUser(Map data) {
_contactbox.add(data);
}
static List getAllUsers11() {
final data = _contactbox.keys.map((key) {
final value = _contactbox.get(key);
print("Checking_Name : $value");
return {
"inid": value["inid"],
"id": value["id"],
"name": value["name"],
"org": value["org"],
"addr": value["addr"],
"phone": value["phone"],
"phone_no": value["phone_no"],
"email": value["email"],
"summarry": value["summarry"],
"speciality": value["speciality"],
"sub_speciality": value["sub_speciality"],
"img_path": value["img_path"]
};
}).toList();
return data.reversed.toList();
}
static List getAllUsers() {
final data = _contactbox.keys.map((key) {
final value = _contactbox.get(key);
print("Checking_Name : $value");
return {
"id": value["id"],
"name": value["name"],
"org": value["org"],
"addr": value["addr"],
"phone": value["phone"],
"phone_no": value["phone_no"],
"email": value["email"],
"affiliations_count": value["affiliations_count"],
"events_count": value["events_count"],
"publications_count": value["publications_count"],
"trail_count": value["trail_count"],
"summarry": value["summarry"],
"license_no": value["license_no"],
"p_suffix": value["p_suffix"],
"speciality": value["speciality"],
"sub_speciality": value["sub_speciality"],
"img_path": value["img_path"]
};
}).toList();
return data;
}
static List getindexUsers() {
final data = _contactbox.keys.map((key) {
final value = _contactbox.get(key);
print("Checking_Name : $value");
return {
"name": value["name"],
"org": value["org"],
"adrr": value["adrr"],
"phone": value["phone"],
"Pphone": value["Pphone"],
"email": value["email"],
"affno": value["affno"],
"eveno": value["eveno"],
"pubno": value["pubno"],
"trailno": value["trailno"]
};
}).toList();
return data.reversed.toList();
}
//static deleteUser112(row) {}
static deleteUser11(id) {
print("Hive_id: $id");
final value1 = _contactbox.delete(id);
print("Getted_valueee: $value1");
}
static Future<void> deleteUser(int selectedremoveIndic) async {
print("storeddelData_id: ${selectedremoveIndic}");
// final userId = "some_user_id"; // Replace with the actual ID you want to query
final value = _contactbox.get(selectedremoveIndic - 1);
print("ValueeeGet: $value");
if (value == null) {
final value1 = _contactbox.get(selectedremoveIndic);
print("Valueee11Get: $value1");
print("UniqueId11 : ${value["inid"]}");
} else {
final value1 = _contactbox.get(2);
print("Valueee11Get: $value1");
print("UniqueId111 : ${value["inid"]}");
}
// print(await _contactbox.getAt(selectedremoveIndic));
// int data = selectedremoveIndic;
// final storeddelData = _contactbox.get(data);
// print("storeddelData_iss: $storeddelData");
// if (storeddelData != null) {
// print("I_amNotnull ${storeddelData["id"]}");
// _contactbox.deleteAt(storeddelData["id"]);
//}
// _hiveBox.delete(dataDel.id);
// _contactbox.deleteAt(selectedremoveIndic);
// final data = _contactbox.keys.map((_contactbox) {
// final value = _contactbox.get(selectedremoveIndic);
// print("Del_valuee_is: ${value}");
// });
}
// void deleteUser(String userId) {
// var _contactbox = Hive.box('contactBox');
// // Find the key corresponding to the userId
// for (var key in _contactbox.keys) {
// final value = _contactbox.get(key);
// if (value["id"] == userId) {
// _contactbox.delete(key);
// print("Deleted user with id: $userId");
// break; // Exit the loop once the item is deleted
// }
// }
// }
// static void deleteUser(int selectedremoveIndic) {
// print("I_Am: selectedremoveIndic: ${selectedremoveIndic}");
// // final data = _contactbox.keys.map((key) {
// final value = _contactbox.get(selectedremoveIndic);
// _contactbox.deleteAt(selectedremoveIndic);
// // if (value["id"] == selectedremoveIndic) {
// // print("I_Am: selectedremoveIndicnew: ${value["name"]}");
// // }
// // });
// }
// static addno(int selectedRowId) {
// // final box1 = Hive.box("mycontact");
// print("SelectedStoredvaluessss: $selectedRowId");
// box1.add(selectedRowId);
// }
// static removeno(int selectedRowId) {
// // final box1 = Hive.box("mycontact");
// print("SelectedStoredvaluessss: $selectedRowId");
// box1.deleteAt(selectedRowId);
// }
// static getno() {
// // final box1 = Hive.box("mycontact");
// return box1.values;
// }
static storehcpdata(Map data) {
apihcpdata.add(data);
}
static gethcpdata() {
return apihcpdata.values.toList();
}
static Future<List> getindexUser(String text) async {
print("Text_issssssS: $text");
// final value = _contactbox.get(int.parse(text));
// print("Checking_Name1111 : $value");
// final data = _contactbox.keys.map((key) {
// var contactBox =
// await Hive.openBox('contacts'); // Replace 'contacts' with your box name
final value = _contactbox.values;
print("Checking_Name : $value");
print("Checking_Name : ${value.contains(text)}");
// final dataa = value.get(text);
// return {
// "name": value["name"],
// "org": value["org"],
// "adrr": value["adrr"],
// "phone": value["phone"],
// "Pphone": value["Pphone"],
// "email": value["email"],
// "affno": value["affno"],
// "eveno": value["eveno"],
// "pubno": value["pubno"],
// "trailno": value["trailno"]
// };
// }).toList();
// print("Check_data_is: $data");
return value.toList();
}
static getuser(int selectedremoveIndic) {
final data = _contactbox.keys.map((selectedremoveIndic) {
final value = _contactbox.get(selectedremoveIndic);
print("Checking_Name111 : $value");
return {
"inid": value["inid"],
"id": value["id"],
"name": value["name"],
"org": value["org"],
"addr": value["addr"],
"phone": value["phone"],
"phone_no": value["phone_no"],
"email": value["email"],
"summarry": value["summarry"],
"speciality": value["speciality"],
"sub_speciality": value["sub_speciality"],
"img_path": value["img_path"]
};
}).toList();
return data;
}
}