2021-06-24 23:10:45 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
|
|
|
class ErrorHandler extends ChangeNotifier {
|
|
|
|
// General Error Types
|
|
|
|
static const String successErrorType = "success";
|
|
|
|
|
|
|
|
// Add Contact Specific Errors...
|
2021-12-18 00:54:30 +00:00
|
|
|
static const String changePasswordErrorPrefix = "changepassword";
|
2021-06-24 23:10:45 +00:00
|
|
|
static const String invalidImportStringErrorType = "invalid_import_string";
|
|
|
|
static const String contactAlreadyExistsErrorType = "contact_already_exists";
|
|
|
|
|
2021-12-18 00:54:30 +00:00
|
|
|
// ChangePassword
|
|
|
|
bool changePasswordError = false;
|
|
|
|
bool explicitChangePasswordSuccess = false;
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
static const String deleteProfileErrorPrefix = "deleteprofile";
|
|
|
|
bool deleteProfileError = false;
|
|
|
|
bool deleteProfileSuccess = false;
|
|
|
|
|
2021-11-04 01:56:53 +00:00
|
|
|
static const String deletedServerErrorPrefix = "deletedserver";
|
|
|
|
bool deletedServerError = false;
|
|
|
|
bool deletedServerSuccess = false;
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
deleteProfileError = false;
|
|
|
|
deleteProfileSuccess = false;
|
|
|
|
|
|
|
|
deletedServerError = false;
|
|
|
|
deletedServerSuccess = false;
|
|
|
|
|
2021-12-18 00:54:30 +00:00
|
|
|
changePasswordError = false;
|
|
|
|
explicitChangePasswordSuccess = false;
|
|
|
|
|
2021-11-04 01:56:53 +00:00
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
/// Called by the event bus.
|
|
|
|
handleUpdate(String error) {
|
|
|
|
var parts = error.split(".");
|
|
|
|
String prefix = parts[0];
|
|
|
|
String errorType = parts[1];
|
|
|
|
|
|
|
|
switch (prefix) {
|
|
|
|
case deleteProfileErrorPrefix:
|
|
|
|
handleDeleteProfileError(errorType);
|
|
|
|
break;
|
2021-12-18 00:54:30 +00:00
|
|
|
case changePasswordErrorPrefix:
|
|
|
|
handleChangePasswordError(errorType);
|
|
|
|
break;
|
2021-11-04 01:56:53 +00:00
|
|
|
case deletedServerErrorPrefix:
|
|
|
|
handleDeletedServerError(errorType);
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDeleteProfileError(String errorType) {
|
|
|
|
// Reset add contact errors
|
|
|
|
deleteProfileError = false;
|
|
|
|
deleteProfileSuccess = false;
|
|
|
|
|
|
|
|
switch (errorType) {
|
|
|
|
case successErrorType:
|
|
|
|
deleteProfileSuccess = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
deleteProfileError = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-11-04 01:56:53 +00:00
|
|
|
|
2021-12-18 00:54:30 +00:00
|
|
|
handleChangePasswordError(String errorType) {
|
|
|
|
// Reset add contact errors
|
|
|
|
changePasswordError = false;
|
|
|
|
explicitChangePasswordSuccess = false;
|
|
|
|
|
|
|
|
switch (errorType) {
|
|
|
|
case successErrorType:
|
|
|
|
explicitChangePasswordSuccess = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
changePasswordError = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 01:56:53 +00:00
|
|
|
handleDeletedServerError(String errorType) {
|
|
|
|
// reset
|
|
|
|
deletedServerError = false;
|
|
|
|
deletedServerSuccess = false;
|
|
|
|
|
|
|
|
switch (errorType) {
|
|
|
|
case successErrorType:
|
|
|
|
deletedServerSuccess = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
deletedServerError = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|