flutter-bloc-async-api

Convert REST HTTP outcomes into typed Result<T> values for Bloc states.

Updated May 16, 2026
One-click install
npx skills add https://github.com/abdallhMoukdad/flutter-bloc-skills --skill flutter-bloc-async-api
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: flutter-bloc-async-api
Source: https://github.com/abdallhMoukdad/flutter-bloc-skills/tree/main/skills/flutter-bloc-async-api
Command: npx skills add https://github.com/abdallhMoukdad/flutter-bloc-skills --skill flutter-bloc-async-api

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves the problem of wiring REST API calls into Bloc without relying on exceptions, while ensuring HTTP failures map cleanly into consistent, user-friendly UI states.

Core Features & Use Cases

  • Typed Result + Failure contract: Ensures repositories never throw by returning Future<Result<T>> and encoding all error cases in a single Failure union.
  • Laravel-aligned Failure taxonomy: Converts HTTP outcomes into a fixed set of variants, including ValidationFailure for 422 field-error envelopes.
  • Canonical Bloc async handler: Standardizes the event flow to emit Loading, await the repository, then emit Loaded or a message derived from Failure.
  • Refresh with safe cancellation semantics: Uses restartable() so pull-to-refresh cancels obsolete in-flight handling to prevent stale-data flicker.

Quick Start

Ask the assistant to implement a Bloc repository + Failure/Result flow for a new Laravel endpoint that returns validation errors on 422 and a typed success model on success.

Frequently Asked Questions about flutter-bloc-async-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle REST API errors in Flutter Bloc without using try/catch?▼

Handle REST API errors in Flutter Bloc by having repositories return a typed Future<Result<T>> instead of throwing exceptions. Blocs then await this result and emit consistent loading, success, or failure states without needing try/catch blocks at the call site.

How do I map Laravel 422 validation errors to typed Flutter Bloc states?▼

Map Laravel 422 validation errors by converting HTTP outcomes into a fixed Failure union taxonomy. This includes a specific ValidationFailure variant for 422 field-error envelopes, allowing your Flutter Bloc to emit user-friendly failure messages derived directly from the typed error.

What is the best way to cancel in-flight REST requests during pull-to-refresh in Flutter?▼

Cancel in-flight REST requests during pull-to-refresh by applying the restartable() transformer to your Bloc events. This safely cancels obsolete in-flight handling, preventing stale-data flicker when a new refresh or query event is triggered.

How does a sealed Result class work for Flutter REST API calls?▼

A sealed Result class works by encoding all REST API error cases into a single Failure union taxonomy. Repositories return this typed Result, ensuring the Bloc receives either a success value or a categorized failure, standardizing the async event flow.

Does this Flutter Bloc approach work for list loading and pull-to-refresh features?▼

Yes, this approach works specifically for Bloc-driven Flutter features like list loading and pull-to-refresh. It standardizes event flow to emit Loading, await the repository, and then emit Loaded or a failure message, applying restartable() for safe cancellation semantics.