61 lines
1.9 KiB
Dart
61 lines
1.9 KiB
Dart
|
import 'package:dio/dio.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_passvault/constant/constantfile.dart';
|
||
|
import 'package:flutter_passvault/modelclasses/delete_credential_model.dart';
|
||
|
import 'package:flutter_passvault/hive_storage/store_credential_model.dart';
|
||
|
import 'package:flutter_passvault/view_pages/shared_preferance.dart';
|
||
|
import 'package:hive/hive.dart';
|
||
|
|
||
|
class DelCredentialProvider extends ChangeNotifier {
|
||
|
final dio = Dio();
|
||
|
|
||
|
MDeleteCredentialData? _serverResponse;
|
||
|
|
||
|
MDeleteCredentialData? get delcredential => _serverResponse;
|
||
|
|
||
|
final Box<Storedcredential> hivebox =
|
||
|
Hive.box<Storedcredential>('credentialListBox');
|
||
|
|
||
|
Future<MDeleteCredentialData?> postdelcredential() async {
|
||
|
final dataToSendBox = await Hive.openBox<Storedcredential>('dataToSendBox');
|
||
|
|
||
|
print("deleted_values_uid: ${dataToSendBox.values}");
|
||
|
|
||
|
for (var data in dataToSendBox.values) {
|
||
|
print("deleted_dataaa ${data.uid}");
|
||
|
|
||
|
print("deleted_api_name: ${data.name}");
|
||
|
print("deleted_api_uid: ${data.uid}");
|
||
|
|
||
|
String? authtoken = await CustomSharedPreferences.getCustomValue();
|
||
|
|
||
|
print("del_auth_code: $authtoken");
|
||
|
|
||
|
dio.options.headers["Authorization"] = 'Bearer $authtoken';
|
||
|
|
||
|
try {
|
||
|
final response = await dio
|
||
|
.delete("${ApiConstants.newKonectarurl}/creds/${data.uid}");
|
||
|
|
||
|
if (response.statusCode == 200) {
|
||
|
dataToSendBox.delete(data);
|
||
|
print('added successful');
|
||
|
print(response.data);
|
||
|
print(response.data['message']);
|
||
|
|
||
|
_serverResponse = MDeleteCredentialData.fromJson(response.data);
|
||
|
|
||
|
print("server_resposeeeeeeeeeeeeeedel: $_serverResponse");
|
||
|
|
||
|
notifyListeners();
|
||
|
} else {
|
||
|
print('Failed : ${response.statusCode}');
|
||
|
}
|
||
|
} catch (error) {
|
||
|
print('Failed : $error');
|
||
|
}
|
||
|
}
|
||
|
return _serverResponse;
|
||
|
}
|
||
|
}
|