super_utils 0.0.5 copy "super_utils: ^0.0.5" to clipboard
super_utils: ^0.0.5 copied to clipboard

Super flutter utilities and extensions for fast development.

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
  );
}

2
likes
160
points
24
downloads

Publisher

unverified uploader

Weekly Downloads

Super flutter utilities and extensions for fast development.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on super_utils