49 lines
1.3 KiB
Dart
49 lines
1.3 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
|
|
class ErrorHandler extends ChangeNotifier {
|
|
// General Error Types
|
|
static const String successErrorType = "success";
|
|
|
|
// Add Contact Specific Errors...
|
|
static const String addContactErrorPrefix = "addcontact";
|
|
static const String invalidImportStringErrorType = "invalid_import_string";
|
|
static const String contactAlreadyExistsErrorType = "contact_already_exists";
|
|
bool invalidImportStringError = false;
|
|
bool contactAlreadyExistsError = false;
|
|
bool explicitAddContactSuccess = false;
|
|
|
|
/// Called by the event bus.
|
|
handleUpdate(String error) {
|
|
var parts = error.split(".");
|
|
String prefix = parts[0];
|
|
String errorType = parts[1];
|
|
|
|
switch (prefix) {
|
|
case addContactErrorPrefix:
|
|
handleAddContactError(errorType);
|
|
break;
|
|
}
|
|
|
|
notifyListeners();
|
|
}
|
|
|
|
handleAddContactError(String errorType) {
|
|
// Reset add contact errors
|
|
invalidImportStringError = false;
|
|
contactAlreadyExistsError = false;
|
|
explicitAddContactSuccess = false;
|
|
|
|
switch (errorType) {
|
|
case invalidImportStringErrorType:
|
|
invalidImportStringError = true;
|
|
break;
|
|
case contactAlreadyExistsErrorType:
|
|
contactAlreadyExistsError = true;
|
|
break;
|
|
case successErrorType:
|
|
explicitAddContactSuccess = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|