flutter_resultable 0.0.1 copy "flutter_resultable: ^0.0.1" to clipboard
flutter_resultable: ^0.0.1 copied to clipboard

A lightweight Result type for modeling success/failure in Flutter and Dart using sealed classes.

flutter_resultable #

A lightweight, expressive Result type for Flutter and Dart to model success and failure outcomes without exceptions, inspired by functional programming patterns like Either.

Pub Version Build Status License


✨ Features #

  • βœ… Result.success and Result.failure to represent outcomes cleanly.
  • πŸ” Pattern matching via when, map, and maybeWhen (thanks to freezed).
  • ⚑ Strongly typed error and success handling.
  • πŸ’‘ Easily testable and composable.
  • πŸͺΆ Minimal, clean API.

πŸ“¦ Installation #

Add this to your pubspec.yaml:

dependencies:
  flutter_resultable: ^1.0.0

Then run:

flutter pub get

πŸ”§ Usage #

Define a result-returning function #

import 'package:flutter_resultable/flutter_resultable.dart';

Result<String, int> divide(int a, int b) {
  if (b == 0) return Result.failure("Division by zero");
  return Result.success(a ~/ b);
}

Handle with pattern matching #

final result = divide(10, 2);

result.when(
  failure: (error) => print("Error: $error"),
  success: (value) => print("Result: $value"),
);

Using maybeWhen #

result.maybeWhen(
  success: (value) => print("Success with $value"),
  orElse: () => print("Something went wrong"),
);

πŸ“˜ API #

sealed class Result<F, S> {
  const factory Result.failure(F failure) = Failure<F, S>;
  const factory Result.success(S success) = Success<F, S>;
}
  • Result.failure(F) β†’ represents a failure result.
  • Result.success(S) β†’ represents a successful result.

πŸ› οΈ Generated Code #

This package uses freezed. To generate code locally (for contributors):

flutter pub run build_runner build --delete-conflicting-outputs

πŸ“„ License #

MIT License


πŸ’° Support #

If you find this project helpful, consider sponsoring me on GitHub πŸ’–


πŸ™Œ Contributing #

Contributions, ideas, and pull requests are welcome. Let’s make flutter_resultable better together!



3
likes
0
points
44
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight Result type for modeling success/failure in Flutter and Dart using sealed classes.

Repository (GitHub)
View/report issues

Topics

#result #either #functional #error-handling #flutter

Funding

Consider supporting this project:

github.com

License

unknown (license)

Dependencies

flutter, freezed_annotation

More

Packages that depend on flutter_resultable