flutter_result

Last updated:

0 purchases

flutter_result Image
flutter_result Images
Add to Cart

Description:

flutter result

flutter_result #
A simple and lightweight package that provides a Result type for handling success and error cases in Flutter and Dart. This package is inspired by the Either type in the dartz package.
Features #

Simple and lightweight Result type
Supports both success and error cases
Easy to integrate into existing Flutter and Dart projects

Installation #
To install this package, add the following dependency to your pubspec.yaml file:
dependencies:
flutter_result: ^0.0.1
copied to clipboard
Then run flutter pub get to download the package.
Usage #
Here's an example of how to use the Result type in your code:
import 'package:result_type/result_type.dart';

Result<String, Exception> getData() {
try {
// fetch data from the server
return Result.success('data');
} catch (e) {
return Result.error(Exception('Failed to fetch data'));
}
}

void main() {
final result = getData();
result.open(
(onSuccess) => print('Data : $onSuccess'),
(onError) => print('Error : $onError'),
);
}

copied to clipboard
In this example, the getData function returns a Result object that contains either a String value (in the case of success) or an Exception object (in the case of an error). The open method is then used to handle each case separately.
Contributing #
To report bugs, suggest new features, or contribute code to this package, please open an issue or a pull request on Github.
License #
This package is released under the MIT License.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.