fix importBundle error handling and dupping of events
continuous-integration/drone/pr Build is running
Details
continuous-integration/drone/pr Build is running
Details
This commit is contained in:
parent
191065f51c
commit
5d09341277
|
@ -1 +1 @@
|
||||||
2022-07-22-12-41-v1.8.0-7-g7b3e842
|
2022-08-13-14-33-v1.8.0-10-gb99e35e
|
|
@ -1 +1 @@
|
||||||
2022-07-22-16-41-v1.8.0-7-g7b3e842
|
2022-08-13-18-34-v1.8.0-10-gb99e35e
|
|
@ -5,13 +5,9 @@ class ErrorHandler extends ChangeNotifier {
|
||||||
static const String successErrorType = "success";
|
static const String successErrorType = "success";
|
||||||
|
|
||||||
// Add Contact Specific Errors...
|
// Add Contact Specific Errors...
|
||||||
static const String addContactErrorPrefix = "addcontact";
|
|
||||||
static const String changePasswordErrorPrefix = "changepassword";
|
static const String changePasswordErrorPrefix = "changepassword";
|
||||||
static const String invalidImportStringErrorType = "invalid_import_string";
|
static const String invalidImportStringErrorType = "invalid_import_string";
|
||||||
static const String contactAlreadyExistsErrorType = "contact_already_exists";
|
static const String contactAlreadyExistsErrorType = "contact_already_exists";
|
||||||
bool invalidImportStringError = false;
|
|
||||||
bool contactAlreadyExistsError = false;
|
|
||||||
bool explicitAddContactSuccess = false;
|
|
||||||
|
|
||||||
// ChangePassword
|
// ChangePassword
|
||||||
bool changePasswordError = false;
|
bool changePasswordError = false;
|
||||||
|
@ -31,10 +27,6 @@ class ErrorHandler extends ChangeNotifier {
|
||||||
bool deletedServerSuccess = false;
|
bool deletedServerSuccess = false;
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
invalidImportStringError = false;
|
|
||||||
contactAlreadyExistsError = false;
|
|
||||||
explicitAddContactSuccess = false;
|
|
||||||
|
|
||||||
importBundleError = false;
|
importBundleError = false;
|
||||||
importBundleSuccess = false;
|
importBundleSuccess = false;
|
||||||
|
|
||||||
|
@ -57,9 +49,6 @@ class ErrorHandler extends ChangeNotifier {
|
||||||
String errorType = parts[1];
|
String errorType = parts[1];
|
||||||
|
|
||||||
switch (prefix) {
|
switch (prefix) {
|
||||||
case addContactErrorPrefix:
|
|
||||||
handleAddContactError(errorType);
|
|
||||||
break;
|
|
||||||
case importBundleErrorPrefix:
|
case importBundleErrorPrefix:
|
||||||
handleImportBundleError(errorType);
|
handleImportBundleError(errorType);
|
||||||
break;
|
break;
|
||||||
|
@ -76,26 +65,6 @@ class ErrorHandler extends ChangeNotifier {
|
||||||
notifyListeners();
|
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;
|
|
||||||
importBundleSuccess = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleImportBundleError(String errorType) {
|
handleImportBundleError(String errorType) {
|
||||||
// Reset add contact errors
|
// Reset add contact errors
|
||||||
importBundleError = false;
|
importBundleError = false;
|
||||||
|
|
|
@ -36,6 +36,9 @@ class _AddContactViewState extends State<AddContactView> {
|
||||||
final ctrlrContact = TextEditingController(text: "");
|
final ctrlrContact = TextEditingController(text: "");
|
||||||
final ctrlrGroupName = TextEditingController(text: "");
|
final ctrlrGroupName = TextEditingController(text: "");
|
||||||
String server = "";
|
String server = "";
|
||||||
|
// flutter textfield onChange often fires twice and since we need contexts, we can't easily use a controler/listener
|
||||||
|
String lastContactValue = "";
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -144,34 +147,41 @@ class _AddContactViewState extends State<AddContactView> {
|
||||||
),
|
),
|
||||||
CwtchTextField(
|
CwtchTextField(
|
||||||
testKey: Key("txtAddP2P"),
|
testKey: Key("txtAddP2P"),
|
||||||
|
key: Key("txtAddP2P"),
|
||||||
controller: ctrlrContact,
|
controller: ctrlrContact,
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value == "") {
|
if (value == "") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (globalErrorHandler.invalidImportStringError) {
|
if (globalErrorHandler.importBundleError) {
|
||||||
return AppLocalizations.of(context)!.invalidImportString;
|
return AppLocalizations.of(context)!.invalidImportString;
|
||||||
} else if (globalErrorHandler.contactAlreadyExistsError) {
|
} else if (globalErrorHandler.importBundleSuccess) { return null; }
|
||||||
return AppLocalizations.of(context)!.contactAlreadyExists;
|
|
||||||
} else if (globalErrorHandler.explicitAddContactSuccess) {}
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
onChanged: (String importBundle) async {
|
onChanged: (String importBundle) async {
|
||||||
var profileOnion = Provider.of<ProfileInfoState>(bcontext, listen: false).onion;
|
if (lastContactValue != importBundle) {
|
||||||
Provider.of<FlwtchState>(bcontext, listen: false).cwtch.ImportBundle(profileOnion, importBundle.replaceFirst("cwtch:", ""));
|
lastContactValue = importBundle;
|
||||||
|
var profileOnion = Provider
|
||||||
|
.of<ProfileInfoState>(bcontext, listen: false)
|
||||||
|
.onion;
|
||||||
|
Provider
|
||||||
|
.of<FlwtchState>(bcontext, listen: false)
|
||||||
|
.cwtch
|
||||||
|
.ImportBundle(profileOnion, importBundle.replaceFirst("cwtch:", ""));
|
||||||
|
|
||||||
Future.delayed(const Duration(milliseconds: 500), () {
|
Future.delayed(const Duration(milliseconds: 500), () {
|
||||||
if (globalErrorHandler.importBundleSuccess) {
|
if (globalErrorHandler.importBundleSuccess) {
|
||||||
// TODO: This isn't ideal, but because onChange can be fired during this future check
|
// TODO: This isn't ideal, but because onChange can be fired during this future check
|
||||||
// and because the context can change after being popped we have this kind of double assertion...
|
// and because the context can change after being popped we have this kind of double assertion...
|
||||||
// There is probably a better pattern to handle this...
|
// There is probably a better pattern to handle this...
|
||||||
if (AppLocalizations.of(bcontext) != null) {
|
if (AppLocalizations.of(bcontext) != null) {
|
||||||
final snackBar = SnackBar(content: Text(AppLocalizations.of(bcontext)!.successfullAddedContact + importBundle));
|
final snackBar = SnackBar(content: Text(AppLocalizations.of(bcontext)!.successfullAddedContact + importBundle));
|
||||||
ScaffoldMessenger.of(bcontext).showSnackBar(snackBar);
|
ScaffoldMessenger.of(bcontext).showSnackBar(snackBar);
|
||||||
Navigator.popUntil(bcontext, (route) => route.settings.name == "conversations");
|
Navigator.popUntil(bcontext, (route) => route.settings.name == "conversations");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
},
|
},
|
||||||
hintText: '',
|
hintText: '',
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue