super_utils

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

super utils

Super Utils #

Useful APIs #
Error Handling #
An extension method for handling the result of a [Future] with success and error callbacks.
The result method allows you to provide two callbacks: one for handling the success case when the [Future] completes successfully, and one for handling the error case when an exception occurs.
Example usage:
Future<int> fetchNumber() async {
// Simulating an asynchronous operation
await Future.delayed(Duration(seconds: 2));

// Simulating an error
throw Failure('Failed to fetch number');
}

void handleSuccess(int number) {
print('Fetched number: $number');
}

void handleError(Failure error) {
print('Error occurred: ${error.message}');
}

void main() {
fetchNumber().result(handleError, handleSuccess);

// or

final request = fetchNumber();

request.result<Failure, int>(
(e) => print('Error occurred: ${e.message}'); // could replace `e` with error
(s) => print('Fetched number: $s'); // could replace `s` with number
);
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.