result_dart
2.2.0, released 8 months ago by flutterando.com.br
Kotlin and Swift inspired Result class for error handling in Dart and Flutter.
What it does
Provides a Result and AsyncResult implementation to encapsulate success or failure values, reducing the need for try-catch blocks. Includes operators like map, flatMap, fold, and recover for transforming and handling outcomes.
AI-written summary of version 2.2.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want to return success or failure states cleanly without throwing exceptions.
- You need functional error handling operators like map, flatMap, and fold.
- You are writing asynchronous functions that can fail and want to use AsyncResult.
Skip it when
- Your architecture heavily relies on throwing and catching exceptions across the entire codebase.
- You already use another functional programming package with its own comprehensive Either or Result type like dartz or fpdart.
Strengths
- Reduces boilerplate by defaulting failure types to Exception.
- Includes a wide range of transformation and recovery operators.
- Supports asynchronous workflows via AsyncResult typedef.
Weaknesses
- Does not provide full functional programming suites like dartz or fpdart.
- Requires adopting a Result return type convention throughout the codebase.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
Result<String> getSomethingPretty() {
if (isOk) {
return Success('OK!');
} else {
return Failure(Exception('Not Ok!'));
}
}Alternatives
Packages that do the same job and could replace result_dart.
- multiple_result
A Result type for Dart inspired by dartz's Either and Kotlin's sealed classes.
62Compare - jni
Provides Dart/Flutter bindings to call native Java code via JNI.
90Compare - apollovm
Portable multi-language VM to parse, run, translate, and compile Dart, Java, Kotlin, Go, C#, JS, and Python.
76Compare - dart_scope_functions
Kotlin-inspired scope functions like also, let, takeIf, and run for executing code blocks on objects.
74Compare
Works with
Packages commonly used together with result_dart: ones it builds on, ones built on it, and its own family.