DiscoverModule/lib/contacts_module/hive_fun.dart

273 lines
7.9 KiB
Dart
Raw Permalink Normal View History

2024-10-07 12:41:28 +00:00
// import 'package:discover_module/storage_hive/kol_info/kol_info_model_hive.dart';
2024-06-27 08:38:43 +00:00
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");
2024-10-07 12:41:28 +00:00
static final apihcpdata123 = Hive.box('kolshive');
2024-06-27 08:38:43 +00:00
static createUser(Map data) {
_contactbox.add(data);
}
2024-08-30 12:24:54 +00:00
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();
}
2024-06-27 08:38:43 +00:00
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"],
2024-08-30 12:24:54 +00:00
"sub_speciality": value["sub_speciality"],
"img_path": value["img_path"]
2024-06-27 08:38:43 +00:00
};
}).toList();
2024-08-30 12:24:54 +00:00
return data;
2024-06-27 08:38:43 +00:00
}
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();
}
2024-08-30 12:24:54 +00:00
//static deleteUser112(row) {}
2024-06-27 08:38:43 +00:00
2024-10-07 12:41:28 +00:00
static deleteUser11(id) async {
2024-08-30 12:24:54 +00:00
print("Hive_id: $id");
2024-06-27 08:38:43 +00:00
2024-10-07 12:41:28 +00:00
for (var entry in _contactbox.toMap().entries) {
var contactData = entry.value;
print("Selected_del_value: $contactData");
if (contactData['id'] == id) {
print("entry.keyentry.key: ${entry.key}.");
// Found the contact with the matching id
await _contactbox.delete(entry.key); // Delete by key
print("Record with id $id has been deleted.");
return; // Exit the function after deletion
}
}
2024-08-30 12:24:54 +00:00
}
2024-06-27 08:38:43 +00:00
2024-08-30 12:24:54 +00:00
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"]}");
}
2024-06-27 08:38:43 +00:00
}
static storehcpdata(Map data) {
apihcpdata.add(data);
}
static gethcpdata() {
2024-08-30 12:24:54 +00:00
return apihcpdata.values.toList();
2024-06-27 08:38:43 +00:00
}
2024-10-07 12:41:28 +00:00
static List getindexUser(String query) {
//static getindexUser(String text) async {
print("Text_issssssS: $query");
final value = _contactbox.values.toList();
print("Checking_Name_Offline_Searchh : ${value}");
// final offlinesearch1 = value.map((e) => e["name"].toString()).toList();
// print("Checking_offlinesearch1 : ${offlinesearch1}");
List data = value
.where((hcp) =>
hcp['name'].toLowerCase().contains(query.toLowerCase()) ||
hcp['speciality'].toLowerCase().contains(query.toLowerCase()) ||
hcp['addr'].toLowerCase().contains(query.toLowerCase()))
.toList();
print("Checking_Name_data : ${data}");
return data.toList();
2024-06-27 08:38:43 +00:00
}
2024-08-30 12:24:54 +00:00
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;
}
2024-10-07 12:41:28 +00:00
static getAllhcpdata(String? option) {
List myhcpname = _contactbox.values.toList();
if (option == "HCP Name") {
return myhcpname.map((e) => e["name"].toString()).toList();
} else {
return myhcpname.map((e) => e["speciality"].toString()).toList();
}
}
static List OfflineStored_getindexUser(String query) {
//static getindexUser(String text) async {
print("Text_issssssS: $query");
final value = apihcpdata123.values.toList();
print("Checking_Name_Offline_Searchh : ${value}");
// final offlinesearch1 = value.map((e) => e["name"].toString()).toList();
// print("Checking_offlinesearch1 : ${offlinesearch1}");
List data = value
.where((hcp) =>
hcp['name'].toLowerCase().contains(query.toLowerCase()) ||
// (hcp['speciality'].toLowerCase().contains(query.toLowerCase()) ??
// hcp['spl'].toLowerCase().contains(query.toLowerCase())) ||
hcp['speciality'].toLowerCase().contains(query.toLowerCase()) ||
hcp['addr'].toLowerCase().contains(query.toLowerCase()))
.toList();
print("Checking_Name_data : ${data}");
return data.toList();
}
static Map<String, dynamic>? findRecordById1(String selectedIndic) {
final list = _contactbox.values.toList();
return list
.firstWhere((element) => element['id'] == int.parse(selectedIndic));
}
static savemyContact(Map<String, dynamic> row) async {
print("CheckingRowww ${row!["email"]}");
final value1 = await _contactbox.values.toList();
List value11 = await value1
.where((element) => element["email"] == row["email"])
.toList();
print("Getted_valueee: ${value11}");
if (value11.isEmpty) {
print("Getted_valueee_imaEmpty");
Map<String, dynamic> data = await {
"id": row["id"],
"name": row["name"],
"org": row["org"],
"addr": row["addr"],
"phone": row["phone"],
"phone_no": row["phone_no"],
"email": row["email"],
"summarry": row["summarry"],
"speciality": row["speciality"],
"sub_speciality": row["sub_speciality"],
2024-11-22 10:38:43 +00:00
"img_path": row["img_path"],
"loc_count": "10",
2024-10-07 12:41:28 +00:00
};
print("Inserting_data_is: $data");
await _contactbox.put(await getNextAutoIncrementValue(), data);
// await _contactbox.add(row);
}
}
static Future<int> getNextAutoIncrementValue() async {
var counterBox = await Hive.openBox<int>('counterBox');
if (!counterBox.containsKey('counter')) {
counterBox.put('counter', 0);
}
int? counter = counterBox.get('counter');
counterBox.put('counter', counter! + 1);
await counterBox.close();
return counter;
}
2024-06-27 08:38:43 +00:00
}