177 lines
5.1 KiB
Dart
177 lines
5.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_passvault/hive_storage/store_credential_model.dart';
|
|
import 'package:hive/hive.dart';
|
|
|
|
class HiveDataRepository extends ChangeNotifier {
|
|
final Box<Storedcredential> _hiveBox;
|
|
|
|
List<Storedcredential> _searchResults = [];
|
|
|
|
HiveDataRepository(this._hiveBox) {
|
|
_searchResults = getAllDataFromHive(); // Initialize with all data
|
|
}
|
|
|
|
List<Storedcredential> getAllDataFromHive() {
|
|
print("Stored_ALL_valuesssss : ${_hiveBox.values.toList()}");
|
|
print(
|
|
"Stored_ALL_valuesssss_leangthhh : ${_hiveBox.values.toList().length}");
|
|
|
|
return _hiveBox.values.toList();
|
|
}
|
|
|
|
List<Storedcredential> getAllofflineData() {
|
|
print(
|
|
"Stored_only offlineALL_valuesssss : ${_hiveBox.values.where((data) => data.isOfflinecreated).toList()}");
|
|
print(
|
|
"Stored_ALL_offvaluesssss_leangthhh : ${_hiveBox.values.toList().length}");
|
|
print("Stored_ALL_offvaluesssss_toList : ${_hiveBox.values.toList()}");
|
|
var keyToRetrieve =
|
|
'isOfflinecreated'; // Replace with the key you want to retrieve
|
|
|
|
print("get_bool)_valuess: ${_hiveBox.get(keyToRetrieve)}");
|
|
|
|
getAllDataFromHive();
|
|
|
|
return _hiveBox.values.where((data) => data.isOfflinecreated).toList();
|
|
}
|
|
|
|
void addOfflineData(Storedcredential data) async {
|
|
print("append_dataaaaaa_issss : ${data.isOfflinecreated}");
|
|
|
|
print(
|
|
"Beforee Stored_ALL_valuesssss_leangthhh : ${_hiveBox.values.toList().length}");
|
|
|
|
_hiveBox.put(data.id, data);
|
|
|
|
notifyListeners();
|
|
|
|
getAllDataFromHive();
|
|
}
|
|
|
|
void updateOfflineData(Storedcredential data) async {
|
|
print(
|
|
"Beforee Stored_ALL_valuesssss_leangthhh : ${_hiveBox.values.toList().length}");
|
|
var jsonKeys = _hiveBox.keys.toList();
|
|
print("jsonkeyss: $jsonKeys");
|
|
|
|
Storedcredential? storedData = _hiveBox.get(data.id);
|
|
|
|
print("data.id : ${data.id}");
|
|
print("data.uid : ${data.uid}");
|
|
|
|
print("Stored_idd: ${storedData?.id}");
|
|
print("Stored_name: ${storedData?.name}");
|
|
|
|
if (storedData != null) {
|
|
storedData.username = data.username;
|
|
storedData.password = data.password;
|
|
storedData.name = data.name;
|
|
|
|
storedData.detail = data.detail;
|
|
|
|
// if (data.uid == 0) {
|
|
await _hiveBox.put(data.id, data);
|
|
// } else {
|
|
// await _hiveBox.put(data.uid, data);
|
|
// }
|
|
|
|
print("successsfully updateddd");
|
|
|
|
notifyListeners();
|
|
}
|
|
getAllDataFromHive();
|
|
}
|
|
|
|
Future<HiveDataRepository?> delofflinecredential(
|
|
Storedcredential dataDel) async {
|
|
Storedcredential? storeddelData = _hiveBox.get(dataDel.id);
|
|
if (storeddelData != null) {
|
|
_hiveBox.delete(dataDel.id);
|
|
|
|
print("Dell_data.id : ${dataDel.id}");
|
|
print("uniq_id_Dell_data.id : ${storeddelData.uid}");
|
|
|
|
final dataToSendBox =
|
|
await Hive.openBox<Storedcredential>('dataToSendBox');
|
|
dataToSendBox.add(storeddelData);
|
|
|
|
notifyListeners();
|
|
}
|
|
|
|
getAllDataFromHive();
|
|
|
|
return null;
|
|
}
|
|
|
|
Future<void> openHiveBoxAndRetrieveData() async {
|
|
print("Stored_ALL_offvaluesssss_toList : ${_hiveBox.values.toList()}");
|
|
|
|
var allRecords = _hiveBox.values.toList();
|
|
|
|
var unsyncedRecords = allRecords
|
|
.where((record) =>
|
|
record.issync == false && record.isOfflinedelete == true)
|
|
.toList();
|
|
|
|
print("Stored_DeleteunsyncedRecords : $unsyncedRecords");
|
|
|
|
print("Stored_unsyncedRecords : $unsyncedRecords");
|
|
}
|
|
|
|
void adduserid(List<int> getofflineselecteduser, int? credentialid) async {
|
|
Storedcredential? storedDatacid = _hiveBox.get(credentialid);
|
|
print("stored_cid : ${storedDatacid!.name}");
|
|
|
|
print("getofflineselecteduser: $getofflineselecteduser");
|
|
print("getofflineselectedusercredentialid: $credentialid");
|
|
|
|
storedDatacid.sharedUserIds = getofflineselecteduser;
|
|
|
|
print("sharedUserIds_isss : ${storedDatacid.sharedUserIds}");
|
|
|
|
await _hiveBox.put(credentialid, storedDatacid);
|
|
|
|
//getAllDataFromHive();
|
|
}
|
|
|
|
List<int> getselecteduserid(int? credentialid) {
|
|
Storedcredential? getstoredData = _hiveBox.get(credentialid);
|
|
if (getstoredData != null) {
|
|
print("get_checked_list: ${getstoredData.sharedUserIds}");
|
|
print("get_checked_list: ${getstoredData.name}");
|
|
print("get_checked_list: ${getstoredData.uid}");
|
|
return getstoredData.sharedUserIds;
|
|
}
|
|
return [];
|
|
}
|
|
|
|
// List<Storedcredential> searchInHive(String query) {
|
|
// var data = _hiveBox.values
|
|
// .where((data) => data.name.toLowerCase().contains(query.toLowerCase()))
|
|
// .toList();
|
|
|
|
// print("return data : $data");
|
|
|
|
// return _hiveBox.values
|
|
// .where((data) => data.name.toLowerCase().contains(query.toLowerCase()))
|
|
// .toList();
|
|
// }
|
|
|
|
List<Storedcredential> get searchResults => _searchResults;
|
|
|
|
void searchInHive(String query) {
|
|
_searchResults = _hiveBox.values
|
|
.where((data) => data.name.toLowerCase().contains(query.toLowerCase()))
|
|
.toList();
|
|
|
|
notifyListeners();
|
|
|
|
print("return data : $_searchResults");
|
|
print("return data : $searchResults");
|
|
|
|
//return searchResults;
|
|
}
|
|
}
|