273 lines
7.9 KiB
Dart
273 lines
7.9 KiB
Dart
// import 'package:discover_module/storage_hive/kol_info/kol_info_model_hive.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 final apihcpdata123 = Hive.box('kolshive');
|
|
|
|
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) async {
|
|
print("Hive_id: $id");
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|
|
|
|
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"]}");
|
|
}
|
|
}
|
|
|
|
static storehcpdata(Map data) {
|
|
apihcpdata.add(data);
|
|
}
|
|
|
|
static gethcpdata() {
|
|
return apihcpdata.values.toList();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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"],
|
|
"img_path": row["img_path"],
|
|
"loc_count": "10",
|
|
};
|
|
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;
|
|
}
|
|
}
|