error_handler_gen 1.0.0 copy "error_handler_gen: ^1.0.0" to clipboard
error_handler_gen: ^1.0.0 copied to clipboard

A Flutter package for simplified error handling and result type management using functional programming patterns.

Error Handler Gen Logo

Result<T, E> - Type-Safe Error Handling for Dart #

A lightweight, type-safe sealed class for functional error handling in Dart. Eliminate exceptions and embrace explicit error handling with a clean, composable API.

Installation #

Add to your pubspec.yaml:

error_handler_gen:
  git:
    url: https://github.com/gen2-eslam/error_handler_gen.git

Features #

  • Type-safe - Compile-time safety for success and error types
  • Sealed class - Exhaustive pattern matching support
  • Async ready - Full support for async operations
  • Functional - Composable operations with map, flatMap, etc.
  • Zero dependencies - Pure Dart implementation

Usage/Examples #

import 'package:error_handler_gen/error_handler_gen.dart';
import 'package:dio/dio.dart';

void main() async {
  // Create instance of Result with generic type parameters
  Result<Response, String> res;
  final dio = Dio();

  // Call Result.excuteAsync or Result.excute    
  res = await Result.excuteAsync<Response, Response, String>(
    executeableFunction: () async {
      var res = await dio.get("https://dart.dev");
      return res;
    },
    onError: (error) {
      return Error<Response, String>(error.toString());
    },
    onSuccess: (data) {
      return Success<Response, String>(data);
    },
  );

  // Call res.when to show data
  res.when(
    success: (data) {
      print(data.value.toString());
    },
    error: (error) {
      print(error.value.toString());
    },
  );
}

Video #

https://youtu.be/QV2P_wBSKg4

3
likes
160
points
61
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter package for simplified error handling and result type management using functional programming patterns.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on error_handler_gen