SuccessOrError typedef
A type specifically made for receiving answer from any function which does not return anything, but we need to know whether the function has succeeded or not.
bool - indicates success status.
DocReaderException - in case success status is false
- brief message for developer,
null
otherwise.
Examples(myFunction
returns SuccessOrError):
With error handling:
var (success, error) = await myFunction();
if (success) {
print("success!");
} else {
print("Error: ${error!.message}");
}
Using then:
myFunction().then((response) {
var (success, error) = response;
if (success) {
print("success!");
} else {
print("Error: ${error!.message}");
}
});
Without error handling:
var (success, _) = await myFunction();
if (success) {
print("success!");
}
Most compact:
if ((await myFunction()).$1) print("success");
Implementation
typedef SuccessOrError = (bool, DocReaderException?);