DiscoverModule/lib/contacts_module/storage_hive/speaker_data/crud.speaker.dart

61 lines
1.7 KiB
Dart
Raw Permalink Normal View History

2024-10-07 12:41:28 +00:00
// import 'package:discover_module/storage_hive/speaker_data/speaker_model_hive.dart';
import 'package:discover_module/contacts_module/storage_hive/speaker_data/speaker_model_hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
addSpeaker(List nihlist) async {
var box = await Hive.openBox<Spe>('speahive');
List<Spe> pros = nihlist.map((json) {
return Spe(
id: json.id,
programtopic: json.programtopic,
speakername: json.speakername.toString() ?? '',
role: json.role ?? '',
evaluatorname: json.evaluatorname.toString() ?? '',
programdate: json.programdate.toString() ?? '',
createdAt: json.createdAt.toString() ?? '',
updatedAt: json.updatedAt.toString() ?? '',
);
}).toList();
print("Eduactionnsss ${pros}");
for (var pro in pros) {
print("Storing_Eduactionnsss: ${pro.evaluatorname}");
2024-11-22 10:38:43 +00:00
//await box.put(pro.id, pro); // Use `put` with id as key
await box.put(await getNextAutoIncrementValue(), pro);
2024-10-07 12:41:28 +00:00
}
}
2024-11-22 10:38:43 +00:00
// await box.put(await getNextAutoIncrementValue(), doctor);
// }
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-10-07 12:41:28 +00:00
retrieveidspeaker(int id) async {
var box = await Hive.openBox<Spe>('speahive');
print('Retrive Doctor}');
var pros = box.get(id);
print('Retrive Doctor Procedure123 ${pros}');
List<Spe> datapro = [];
if (pros != null) {
datapro.add(pros); // Add to the list if not null
}
return datapro;
}