Skip to content

fabrik_result

pub.dev

fabrik_result is a minimal result-handling toolkit for Dart and Flutter. It gives you a typed way to model success and failure without relying on exceptions — making your domain logic easier to read, test, and reason about.

Terminal window
dart pub add fabrik_result

Or add it to your pubspec.yaml:

dependencies:
fabrik_result: ^1.0.1

Import it in your Dart files:

import 'package:fabrik_result/fabrik_result.dart';

Either<L, R> is a sealed type that holds either a left value (conventionally failure) or a right value (conventionally success). It makes the possible outcomes of an operation explicit in the return type.

Either<Failure, User> result = await userRepository.getUser(id);
result.fold(
(failure) => showError(failure.message),
(user) => navigateToProfile(user),
);

Constructing values:

// Success
return Right(user);
// Failure
return Left(Failure('User not found'));

Checking the side:

result.isRight // true if success
result.isLeft // true if failure

Unit is a typed void — use it when an operation succeeds but has nothing meaningful to return.

Either<Failure, Unit> result = await settingsRepository.save(settings);
result.fold(
(failure) => showError(failure.message),
(_) => showSuccess('Settings saved'),
);

Instead of returning Either<Failure, void> (which isn’t valid in Dart), return Either<Failure, Unit> and use Right(unit) as the success value.


A typical repository method using fabrik_result:

Future<Either<Failure, User>> getUser(String id) async {
try {
final model = await dataSource.fetchUser(id);
return Right(model.toEntity());
} catch (e) {
return Left(Failure(e.toString()));
}
}

try-catchEither
Failure is explicit in signatureNoYes
Caller must handle failureNoYes
Testable without exceptionsHardEasy
ComposableNoYes

fabrik_result is a lightweight alternative to packages like dartz — it provides only Either and Unit, nothing more.