op_result 0.3.0 copy "op_result: ^0.3.0" to clipboard
op_result: ^0.3.0 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> successResult = OpResult.success(
    "User data retrieved",
  );
  final OpResult<String> failureResult = OpResult.failure(
    OpError(
      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
160
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

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on op_result