clean-arch-ui
/clean-arch-ui
Łączy widżety Fluttera ze stanem Cubit lub Bloc, obsługuje ładowanie i błędy, lokalizację i zdarzenia prezentacji w warstwie UI.
- Autor
- aissaserrar ↗
- Repozytorium
- flutter-clean-arch-plugin ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 31.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 3
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 31.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Łączy widżety Fluttera ze stanem Cubit lub Bloc, obsługuje ładowanie i błędy, lokalizację i zdarzenia prezentacji w warstwie UI.
Oryginalny opis (EN)
Use when creating or editing Flutter pages and widgets in a feature (features/<feature>/presentation/ui): connecting widgets to Cubit/Bloc state with BlocBuilder/BlocListener/BlocSelector, providing cubits per page, handling presentation events, error and loading UI, localization, and design system usage.
Jak działa
- Hard rules
- Page structure
- Reading state
- Errors, loading and empty states
- Forms and input
- Navigation
- Analytics and accessibility
- Checklist before finishing
- Bundled files
Podgląd SKILL.md
---
name: clean-arch-ui
description: Use when creating or editing Flutter pages and widgets in a feature (features/<feature>/presentation/ui): connecting widgets to Cubit/Bloc state with BlocBuilder/BlocListener/BlocSelector, providing cubits per page, handling presentation events, error and loading UI, localization, and design system usage.
---
# UI rules: pages and widgets
The UI renders state and forwards user intent. It contains no business logic and no data access.
## Hard rules
- Imports: Flutter, `flutter_bloc`, the feature's own cubit/state, `domain` entities (for display), `design_system`, `l10n`, `core`. **Never `data/`.**
- No HTTP, storage, repository or use-case calls in widgets. Call cubit methods only.
- No business rules or formatting logic that has meaning beyond display. Put it in a use case or entity.
- Strings come from `context.l10n`. No hard-coded user-facing text. Localization stays in the presentation layer: other layers return failures or message models, and the UI maps them to localized text.
- Use **design system components** (`AppButton`, `AppScaffold`, `AppSpinner`, ...). Do not use `material`/`cupertino` widgets directly in feature code. Colors, spacing, text styles come from tokens: no literal colors or magic numbers.
## Page structure
- The public **`<Feature>Page`** is the route entry. It **provides its cubit** and builds the private **`_<Feature>Content`** underneath, so the content can be tested with a mocked cubit.
```dart
// auto_route
@RoutePage()
class TransferPage extends StatelessWidget implements AutoRouteWrapper {
const TransferPage({super.key});
@override
Widget wrappedRoute(BuildContext context) => BlocProvider(
create: (context) => TransferCubit(context.read()),
child: this,
);
@override
Widget build(BuildContext context) => const _TransferContent();
}
```
```dart
// go_router (or any router that builds the page widget): the page provides the cubit itself.
// A page that takes a route parameter passes it on to its cubit.
class AccountPage extends StatelessWidget {
const AccountPage({super.key, required this.accountId});
final String accountId;
@override
Widget build(BuildContext context) => BlocProvider(
create: (context) => AccountCubit(context.read(), accountId),
child: const _AccountContent(),
);
}
```
- Keep `build` small. Split into private widget classes (`_TransferForm`, `_SubmitButton`), not helper methods returning `Widget`.
- Reusable widgets without cubit knowledge take plain parameters and callbacks. Only page-level or feature-level widgets read the cubit. Reusable UI components belong in `design_system`, not in shared code.
- Form cubits are provided with `BlocProvider` and read from context when the feature cubit is created (see `clean-arch-forms`).
## Reading state
- `BlocBuilder` for rendering; use `buildWhen` or `BlocSelector` to rebuild only what changed.
- **Switch exhaustively over sealed states**; no `if (state is X) ... else ...` chains with a catch-all.
- **One-off effects** (navigate, dialog, snackbar) come from presentation events: use `BlocPresentationListener`. Never do these in `build`. Use `BlocListener` with `listenWhen` only for reacting to state transitions that are not events.
- `context.read<Cubit>()` in callbacks, `context.watch`/`select` in build. Never `read` in `build` to get values you display.
```dart
BlocPresentationListener<TransferCubit, TransferPresentationEvent>(
listener: (context, event) => switch (event) {
TransferPresentationEvent.completed => context.router.maybePop(), // or the go_router equivalent
},
child: BlocBuilder<TransferCubit, TransferState>(
builder: (context, state) => switch (state) {
TransferStateInitial() => const _TransferForm(),
TransferStateFailure(:final failure) => _TransferForm(failure: failure),
TransferStateLoading() => const AppSpinner(),
TransferStateSuccess() => const SizedBox.shrink(),
},
),
)
```
## Errors, loading and empty states
- Define error and loading patterns **once, globally**, and reuse them on every screen (see `references/error-and-loading-patterns.md`): full-screen, part of a screen, next page of a list, and user actions.
- Map `AppFailure` to a user message in the UI layer (one shared helper in `core` or `design_system`), using l10n. Show a **precise** message when it helps the user fix the problem; a generic one only when extra detail would not help.
- Every failure gives the user a way to **retry** (a cubit method). Never leave a screen the user can only escape by going back and navigating again.
- Network errors are handled differently from other errors, with clear feedback and automatic retry when the connection returns (details in the reference).
## Forms and input
- Controllers, focus nodes, animation controllers and global keys are presentation state: keep them in a `StatefulWidget`'s `State` and dispose them properly.
- Forms follow `clean-arch-forms`. Validation rules that are business rules call a use case via the cubit; simple format checks may stay in the form.
- Disable submit while loading; the cubit also guards against double submit.
## Navigation
- Navigate through the router from presentation-event listeners or callbacks. With go_router use the route extensions (`MyRoute(...).go(context)`), not raw paths. Cross-feature navigation uses a route from `router/` or an injected navigation interface, never an import of another feature's page. See `clean-arch-di-routing`.
## Analytics and accessibility
- Pages and tappable widgets carry analytics ids following `clean-arch-observability`.
- Provide `Semantics`/tooltips for icon-only controls; respect text scaling (no fixed heights on text).
## Checklist before finishing
- [ ] No `data/` import, no repository/use-case access in widgets
- [ ] Page provides its cubit; content is a private `_<Feature>Content`
- [ ] Exhaustive `switch` on state; presentation events for side effects
- [ ] All strings from l10n, all styles from design system, no direct `material`/`cupertino` widgets
- [ ] Loading / error+retry / empty states present, using the shared patterns
- [ ] Controllers created in `State` and disposed
- [ ] Widget test with a mocked cubit (see `clean-arch-testing`)
## Bundled files
- `references/ui-checklist.md`: review checklist
- `references/error-and-loading-patterns.md`: reusable error, loading and connectivity patterns
Pliki w paczce (3)
- SKILL.md 6 KB
- references/error-and-loading-patterns.md 2 KB
- references/ui-checklist.md 2 KB
Wersje
W bazie nie ma innych skilli o nazwie clean-arch-ui.
Migawka bazy z 13.11.2026 · wersja paczki 551cedf6488e (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 4 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100clean-arch-presentation
Pisze klasy Cubit i Bloc we Flutterze: stany, zdarzenia, wywołania przypadków użycia, efekty jednorazowe i mapowanie błędów. - 100flutter-bloc
Zarządza stanem Flutter przez Bloc i Cubit: zdarzenia, stany, transformery i testy z bloc_test. - 100bloc
Podaje dobre praktyki zarządzania stanem Bloc we Flutter i Dart: Cubit kontra Bloc, nazewnictwo zdarzeń i stanów, klasy sealed z Equatable, podział Page i View oraz BlocBuilder, BlocListener i BlocSelector wraz z testami. - 100clean-arch-forms
Tworzy formularze we Flutterze z Cubit lub Bloc: cubity pól, czas walidacji, zachowanie przycisku wysyłania i błędy po wysłaniu. - 100bloc
Pomaga tworzyć Cubit i Bloc, modelować stan klasami sealed lub enumami statusu, łączyć BlocBuilder, BlocListener i BlocProvider, pisać testy bloc oraz wybierać między Cubit a Bloc. - 100bloc-cubit
Pomaga w zarządzaniu stanem we Flutterze z Bloc i Cubit: wybór między nimi, współpraca bloc z flutter_bloc, cykl życia, testowanie i bezpieczne ustawienia domyślne.