op_result 0.2.2 copy "op_result: ^0.2.2" to clipboard
op_result: ^0.2.2 copied to clipboard

A generic result type for handling success and error cases in a type-safe manner.

example/op_result_example.dart

import 'package:op_result/op_result.dart';

enum ApiErrorType { unauthorized, notFound, serverError }

void main() {
  final OpResult<String, ApiErrorType> successResult = OpResult.success(
    "User data retrieved",
  );
  final OpResult<String, ApiErrorType> failureResult = OpResult.failure(
    OpResultError(
      type: ApiErrorType.notFound,
      message: "User not found in the system",
    ),
  );

  if (successResult.isSuccess) {
    print("Success: ${successResult.data}");
  }

  if (failureResult.isFailure) {
    print("Error: ${failureResult.error.getErrorMessage()}");
  }
}
1
likes
0
points
62
downloads

Publisher

verified publishercantini.dev

Weekly Downloads

A generic result type for handling success and error cases in a type-safe manner.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on op_result