51 lines
1.6 KiB
Dart
51 lines
1.6 KiB
Dart
import 'package:cheminova/services/api_client.dart';
|
|
import 'package:dio/dio.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../services/api_urls.dart';
|
|
|
|
class ChangePasswordProvider extends ChangeNotifier {
|
|
bool _isLoading = false;
|
|
|
|
final oldPasswordController = TextEditingController();
|
|
final newPasswordController = TextEditingController();
|
|
final confirmPasswordController = TextEditingController();
|
|
|
|
bool get isLoading => _isLoading;
|
|
final _apiClient = ApiClient();
|
|
|
|
void setLoading(bool loading) {
|
|
_isLoading = loading;
|
|
notifyListeners();
|
|
}
|
|
Future<(bool, String)> changePassword() async {
|
|
setLoading(true);
|
|
try {
|
|
Response response = await _apiClient.put(ApiUrls.changePasswordUrl,
|
|
data: {'oldPassword': oldPasswordController.text.trim(),
|
|
'confirmPassword': confirmPasswordController.text.trim(),
|
|
'newPassword': newPasswordController.text.trim()});
|
|
setLoading(false);
|
|
if (response.statusCode == 200) {
|
|
return (true, response.data['message'].toString());
|
|
} else {
|
|
return (false, response.data['message'].toString());
|
|
}
|
|
}
|
|
on DioException catch (e) {
|
|
setLoading(false);
|
|
if (e.response != null && e.response?.data != null) {
|
|
// Extracting the error message from the Dio response
|
|
return (false, e.response!.data['message'].toString());
|
|
} else {
|
|
// When no response or response data is available
|
|
return (false, 'Something went wrong');
|
|
}
|
|
}
|
|
catch (e) {
|
|
setLoading(false);
|
|
return (false, 'Something want wrong');
|
|
}
|
|
}
|
|
|
|
} |