@@ -5,6 +5,11 @@ Result package for dart inspired by the work of [dartz](https://pub.dev/packages
55This package is perfect to those of you who just want the Multiple results
66functionality from dartz. 👌
77
8+ ##### Old version:
9+
10+ If you're looking for a non null-safety version, you can find it in [ here] ( https://github.com/higorlapa/result/tree/no-null-safety )
11+
12+
813## How to use it
914
1015In the return of a function, set it to return a Result type;
@@ -23,13 +28,13 @@ Result<Exception, String> getSomethingPretty() {
2328
2429in return of the function, you just need to return
2530``` dart
26- return Success(" Something Pretty" );
31+ return Success(' Something Pretty' );
2732```
2833
2934or
3035
3136``` dart
32- return Error(Exception(" something ungly happened..." ));
37+ return Error(Exception(' something ugly happened...' ));
3338```
3439
3540The function should look something like this:
@@ -38,9 +43,9 @@ The function should look something like this:
3843
3944Result<Exception, String> getSomethingPretty() {
4045 if(isOk) {
41- return Success(" OK!" );
46+ return Success(' OK!' );
4247 } else {
43- return Error(Exception(" Not Ok!" ));
48+ return Error(Exception(' Not Ok!' ));
4449 }
4550}
4651
@@ -51,13 +56,16 @@ Result<Exception, String> getSomethingPretty() {
5156``` dart
5257void main() {
5358 final result = getSomethingPretty();
54- result.when((error) {
55- // handle the error here
56- print(error);
57- }, (success) {
58- // handle the success here
59- print(success);
60- });
59+ final String message = result.when(
60+ (error) {
61+ // handle the error here
62+ return "error";
63+ }, (success) {
64+ // handle the success here
65+ return "success";
66+ },
67+ );
68+
6169}
6270```
6371
@@ -75,3 +83,33 @@ void main() {
7583}
7684```
7785
86+
87+ #### Handling the Result with ` getSuccess `
88+
89+ ``` dart
90+ void main() {
91+ final result = getSomethingPretty();
92+
93+ String? mySuccessResult;
94+ if (result.isSuccess()) {
95+ mySuccessResult = result.getSuccess();
96+ }
97+ }
98+
99+ ```
100+
101+
102+ #### Handling the Result with ` getError `
103+
104+ ``` dart
105+ void main() {
106+ final result = getSomethingPretty();
107+
108+ Exception? myException;
109+ if (result.isError()) {
110+ myException = result.getError();
111+ }
112+ }
113+ ```
114+
115+
0 commit comments