You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A package inspired by Rust and functional programming, designed to bring structure, clarity, and safety to your Dart applications.
14
-
15
-
Dart traditionally uses nulls and try-catch blocks, which can introduce runtime errors and complicate error handling. In contrast, languages like Rust prioritize safer error handling through types like Result and Option, ensuring explicit handling at compile time.
16
-
17
-
This package introduces Result and Option types to Dart, reducing the reliance on try-catch blocks and nulls. By leveraging these constructs, you can write more predictable, maintainable, and error-resilient code.
18
-
19
-
For a full feature set, please refer to the [API reference](https://pub.dev/documentation/df_safer_dart/).
20
-
21
-
## Usage Example
22
-
23
-
Example of avoiding try-catch blocks in Dart, to produce safer code:
final response = await http.get(Uri.parse('https://api.ipify.org?format=json'));
41
-
// This throws an exception if the status code is not 200.
42
-
PanicIf(response.statusCode != 200, 'Failed to fetch IP address');
43
-
final data = jsonDecode(response.body);
44
-
final ip = data['ip'] as String;
45
-
// Return the result.
46
-
return ip;
47
-
});
48
-
}
49
-
```
50
-
51
-
---
52
-
53
11
## Contributing and Discussions
54
12
55
13
This is an open-source project, and we warmly welcome contributions from everyone, regardless of experience level. Whether you're a seasoned developer or just starting out, contributing to this project is a fantastic way to learn, share your knowledge, and make a meaningful impact on the community.
0 commit comments