op_result 0.3.0
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()}");
}
}