/flutter-clean-riverpod-skills:flutter-result-errorsfrom flutter-clean-riverpod-skills
Provides a sealed AppFailure taxonomy and Result types over result_dart for Flutter data-layer, repository, and provider code. Maps exceptions to user-facing errors with a single catch boundary (RemoteDataSourceGuard) and presentation folding.
Ships in flutter-clean-riverpod-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Nothing throws across a layer boundary. Every data-source and repository
method returns a Result that is either a value or an AppFailure.
Result is not.
Callers cannot forget the failure path.AppFailure is sealed, so a switch over it is exhaustive. Adding a
failure type becomes a compile error everywhere it is not handled.Copy these from this skill's assets/ and replace your_app with the
package name in pubspec.yaml. Add result_dart to dependencies.
| Asset | Destination |
|---|---|
app_failure.dart, result.dart, errors.dart | lib/core/errors/ |
api_exception.dart, remote_data_source_guard.dart | lib/core/network/ |
submission_notifier.dart | lib/core/utils/ |
Feature code imports core/errors/errors.dart, never
package:result_dart directly, so the package stays swappable.
Where a file also imports flutter_riverpod, use
import 'package:flutter_riverpod/flutter_riverpod.dart' hide AsyncResult;
to avoid a name clash with the app typedef.
| Layer | Does | Never |
|---|---|---|
| Remote data source | Wraps every request in guard(...); parses JSON into models | Contains try/catch; returns entities |
| Repository | Calls data sources, maps models → entities with result.map(...) | Catches, throws, or leaks models/DTOs |
| Domain | Pure Dart | Throws or catches |
| Presentation | Folds the Result into UI state | Reads failure.message for UI copy |
class ProfileRemoteDataSourceImpl
with RemoteDataSourceGuard
implements ProfileRemoteDataSource {
ProfileRemoteDataSourceImpl(this._apiClient);
final ApiClient _apiClient;
@override
AsyncResult<ProfileModel> fetchProfile() {
return guard(() async {
final response = await _apiClient.get(ProfileEndpoints.me);
final data = response['data'] as Map<String, dynamic>;
return ProfileModel.fromJson(data);
});
}
}
guard already handles timeouts (→ NetworkFailure), ApiException
(→ via toAppFailure()), and anything else (→ UnknownFailure carrying the
error and stack trace). Do not add a second try/catch around it.
Operations that return no data use AsyncResult<Unit>:
AsyncResult<Unit> deleteAccount() => guard(() async {
await _apiClient.delete(AccountEndpoints.me);
return unit;
});
The repository only converts; it passes failures through untouched.
@override
AsyncResult<Profile> getProfile() async {
final result = await _remote.fetchProfile();
return result.map((model) => model.toEntity());
}
@override
AsyncResult<Unit> deleteAccount() async {
final result = await _remote.deleteAccount();
return result.map((_) => unit);
}
Reads — bridge into Riverpod's AsyncValue. getOrThrow() inside a
provider is the one sanctioned throw: it surfaces as AsyncError to the UI.
class StatsNotifier extends AsyncNotifier<Stats> {
@override
Future<Stats> build() async {
final result = await ref.watch(statsRepositoryProvider).getStats();
return result.getOrThrow();
}
}
Actions (submit, toggle, delete) — extend SubmissionNotifier<T> so a
button press gets loading / data / error state without setState:
class FavoriteSubmissionNotifier extends SubmissionNotifier<Unit> {
Future<void> remove(String id) =>
run(() => ref.read(favoritesProvider.notifier).remove(id));
}
final favoriteSubmissionProvider =
NotifierProvider.autoDispose<FavoriteSubmissionNotifier, AsyncValue<Unit?>>(
FavoriteSubmissionNotifier.new,
);
Idle is AsyncData(null). The notifier is autoDispose so a stale error
resets when the screen is left. run ignores a second call while loading
(double-tap guard) and survives the provider being disposed mid-request.
UI copy comes from l10n keyed on the failure type:
String failureMessage(AppLocalizations l10n, AppFailure failure) =>
switch (failure) {
NetworkFailure() => l10n.errorNetwork,
AuthFailure() => l10n.errorSessionExpired,
CancelledFailure() => '', // an answer, not a fault: stay silent
_ => l10n.errorGeneric,
};
Drop the _ arm if you want the compiler to force every new failure to
be handled. Keep it when a feature-specific mapper falls back to a shared
baseline (match domain failures first, then delegate).
Add a final class XFailure extends AppFailure (with its own kind) when
the UI must treat a case differently from the generic ones, e.g.
CancelledFailure (silent), a store refusing purchases, a social sign-in
sheet dismissed. If the UI would show the same copy as an existing failure,
reuse that one.
kind is a hand-written string, not runtimeType.toString():
minification reduces runtimeType to a letter in release builds.failure.message is for logs only. Never show it to users.UnknownFailure keeps error and stackTrace; report from there.rethrow, never throw in a repository or data source.guard) or add a typed failure.requestTimeout in the data source.Fake the ApiClient, throw an ApiException, assert the Result:
test('maps 401 to AuthFailure', () async {
when(() => api.get(any())).thenThrow(const ApiResponseException(statusCode: 401));
final result = await dataSource.fetchProfile();
expect(result.exceptionOrNull(), isA<AuthFailure>());
});
try/catch or throw in repositories or data sources (outside guard)AsyncResult<…>package:result_dart import in feature codefailure.messagekindWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub ethiel97/flutter-clean-riverpod-skills --plugin flutter-clean-riverpod-skills6 skills in this plugin
/flutter-feature-scaffoldUse when adding a new feature or module to a Flutter app that follows feature-first Clean Architecture (data / domain / presentation) with Riverpod 3 and no code generation for providers, when deciding which layer or folder a file belongs in, or when reviewing dependency direction between layers. Provides the folder layout, per-layer rules, barrel conventions, build order and a scaffold script./flutter-riverpod3Use when writing or reviewing Riverpod 3 code in a Flutter app WITHOUT code generation - choosing a provider type, wiring dependency injection, writing Notifier or AsyncNotifier classes, using ref.watch / read / listen / select, handling disposal, mounted checks and automatic retry, or when someone proposes riverpod_generator, @riverpod, StateNotifier, Bloc, GetIt or the provider package./flutter-sdk-contractsUse when adding, replacing or touching any third-party SDK or platform plugin in a Flutter app (Firebase, Sentry, PostHog, Dio, secure storage, shared_preferences, notifications, share, clipboard, permissions, purchases), or when feature code imports an SDK directly. Defines application-owned contracts (ports), adapters, no-op/composite/recording implementations and their Riverpod wiring./flutter-testingUse when writing or reviewing tests for a Flutter app that uses Riverpod, Result-based repositories and SDKs behind contracts - unit tests for data sources, repositories and notifiers, widget tests with provider overrides, listener tests with recording fakes, golden tests, or deciding between a mock and a fake./flutter-ui-side-effectsUse when a Flutter widget needs navigation, snackbars, dialogs, analytics or any one-shot reaction to a state change, when button callbacks contain context.router / ScaffoldMessenger / analytics calls, when error copy must be shown for a failed action, or when adding a <Feature>Listeners widget. Covers ref.listen listener widgets, per-attempt submission state and mapping failures to user-facing text.Other plugins' skills for the same job