multiple_result 1.0.0 copy "multiple_result: ^1.0.0" to clipboard
multiple_result: ^1.0.0 copied to clipboard

outdated

Result package for Flutter

multiple_result #

Result package for dart inspired by the work of dartz's Either and Kotlin's sealed classes.

This package is perfect to those of you who just want the Multiple results functionality from dartz. 👌

How to use it #

In the return of a function, set it to return a Result type;

Result getSomethingPretty();

then add the Error and the Success types.


Result<Exception, String> getSomethingPretty() {

}

in return of the function, you just need to return

return Success("Something Pretty");

or

return Error(Exception("something ungly happened..."));

The function should look something like this:


Result<Exception, String> getSomethingPretty() {
    if(isOk) {
        return Success("OK!");
    } else {
        return Error(Exception("Not Ok!"));
    }
}

Handling the Result with when

void main() {
    final result = getSomethingPretty();
     result.when((error) {
      // handle the error here
      print(error);
    }, (success) {
      // handle the success here
      print(success);
    });
}

Handling the Result with get

void main() {
    final result = getSomethingPretty();

    String? mySuccessResult;
    if (result.isSuccess()) {
      mySuccessResult = result.get();
    }
}
140
likes
0
pub points
94%
popularity

Publisher

unverified uploader

Result package for Flutter

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on multiple_result