flutter-pro-skills 0.0.0-stage → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE.md +26 -0
- package/README.ar.md +122 -0
- package/README.md +268 -2
- package/install.sh +86 -0
- package/package.json +39 -4
- package/skills/dart-flutter-best-practices/SKILL.md +242 -0
- package/skills/dart-flutter-best-practices/assets/AGENTS-snippet.md +24 -0
- package/skills/dart-flutter-best-practices/assets/analysis_options.yaml +86 -0
- package/skills/dart-flutter-best-practices/references/effective-dart.md +338 -0
- package/skills/dart-flutter-best-practices/scripts/format-dart-hook.sh +48 -0
- package/skills/dart-flutter-review/SKILL.md +342 -0
- package/skills/dart-flutter-review/references/ci.md +212 -0
- package/skills/dart-flutter-review/references/finding-format.md +238 -0
- package/skills/dart-flutter-review/references/review-guide.md +217 -0
- package/skills/dart-flutter-review/references/reviewer-prompts.md +1456 -0
- package/skills/dart-flutter-review/scripts/ci_action.sh +81 -0
- package/skills/dart-flutter-review/scripts/heuristics.py +1135 -0
- package/skills/dart-flutter-review/scripts/review.sh +440 -0
- package/skills/dart-naming/SKILL.md +208 -0
- package/skills/dart-naming/references/naming.md +522 -0
- package/skills/flutter-accessibility/SKILL.md +211 -0
- package/skills/flutter-accessibility/references/placement-by-architecture.md +185 -0
- package/skills/flutter-accessibility/references/review.md +92 -0
- package/skills/flutter-accessibility/references/rules.md +306 -0
- package/skills/flutter-accessibility/references/semantics-and-labels.md +187 -0
- package/skills/flutter-accessibility/references/testing-accessibility.md +152 -0
- package/skills/flutter-accessibility/references/visual-and-input.md +148 -0
- package/skills/flutter-accessibility/scripts/check_accessibility.py +1411 -0
- package/skills/flutter-adaptive-layout/SKILL.md +239 -0
- package/skills/flutter-adaptive-layout/references/input-and-platform.md +221 -0
- package/skills/flutter-adaptive-layout/references/placement-by-architecture.md +86 -0
- package/skills/flutter-adaptive-layout/references/review.md +98 -0
- package/skills/flutter-adaptive-layout/references/rules.md +502 -0
- package/skills/flutter-adaptive-layout/references/size-classes-and-layout.md +326 -0
- package/skills/flutter-adaptive-layout/references/testing-adaptive-layouts.md +158 -0
- package/skills/flutter-adaptive-layout/scripts/check_adaptive.py +1743 -0
- package/skills/flutter-architecture/SKILL.md +276 -0
- package/skills/flutter-architecture/references/anti-patterns/data-and-repositories.md +264 -0
- package/skills/flutter-architecture/references/anti-patterns/dependency-rule.md +314 -0
- package/skills/flutter-architecture/references/anti-patterns/di-and-globals.md +105 -0
- package/skills/flutter-architecture/references/anti-patterns/over-engineering.md +140 -0
- package/skills/flutter-architecture/references/anti-patterns/pattern-specific.md +473 -0
- package/skills/flutter-architecture/references/anti-patterns/presentation.md +411 -0
- package/skills/flutter-architecture/references/anti-patterns/state.md +348 -0
- package/skills/flutter-architecture/references/anti-patterns.md +195 -0
- package/skills/flutter-architecture/references/bloc.md +339 -0
- package/skills/flutter-architecture/references/clean-architecture.md +270 -0
- package/skills/flutter-architecture/references/detect.md +310 -0
- package/skills/flutter-architecture/references/mvc.md +249 -0
- package/skills/flutter-architecture/references/mvn.md +377 -0
- package/skills/flutter-architecture/references/mvvm.md +319 -0
- package/skills/flutter-architecture/references/repository-pattern.md +215 -0
- package/skills/flutter-architecture/references/state-management.md +190 -0
- package/skills/flutter-architecture/scripts/arch_check.py +2546 -0
- package/skills/flutter-design-system/SKILL.md +208 -0
- package/skills/flutter-design-system/references/components-and-placement.md +240 -0
- package/skills/flutter-design-system/references/review.md +92 -0
- package/skills/flutter-design-system/references/rules.md +438 -0
- package/skills/flutter-design-system/references/tokens-and-theming.md +338 -0
- package/skills/flutter-design-system/scripts/check_design_system.py +1517 -0
- package/skills/flutter-error-handling/SKILL.md +190 -0
- package/skills/flutter-error-handling/references/error-flow-by-architecture.md +646 -0
- package/skills/flutter-error-handling/references/global-handlers.md +246 -0
- package/skills/flutter-error-handling/references/result-vs-exceptions.md +302 -0
- package/skills/flutter-error-handling/references/review.md +85 -0
- package/skills/flutter-error-handling/references/rules.md +823 -0
- package/skills/flutter-error-handling/scripts/check_errors.py +2005 -0
- package/skills/flutter-feature-scaffold/SKILL.md +219 -0
- package/skills/flutter-feature-scaffold/assets/templates/bloc/bloc.dart.tmpl +44 -0
- package/skills/flutter-feature-scaffold/assets/templates/bloc/bloc_test.dart.tmpl +41 -0
- package/skills/flutter-feature-scaffold/assets/templates/bloc/event.dart.tmpl +19 -0
- package/skills/flutter-feature-scaffold/assets/templates/bloc/state.dart.tmpl +37 -0
- package/skills/flutter-feature-scaffold/assets/templates/bloc/view.dart.tmpl +55 -0
- package/skills/flutter-feature-scaffold/assets/templates/bloc/view_test.dart.tmpl +29 -0
- package/skills/flutter-feature-scaffold/assets/templates/clean/data_source.dart.tmpl +28 -0
- package/skills/flutter-feature-scaffold/assets/templates/clean/dto.dart.tmpl +24 -0
- package/skills/flutter-feature-scaffold/assets/templates/clean/entity.dart.tmpl +18 -0
- package/skills/flutter-feature-scaffold/assets/templates/clean/repository.dart.tmpl +6 -0
- package/skills/flutter-feature-scaffold/assets/templates/clean/repository_impl.dart.tmpl +26 -0
- package/skills/flutter-feature-scaffold/assets/templates/clean/repository_impl_test.dart.tmpl +60 -0
- package/skills/flutter-feature-scaffold/assets/templates/clean/usecase.dart.tmpl +13 -0
- package/skills/flutter-feature-scaffold/assets/templates/clean/usecase_test.dart.tmpl +21 -0
- package/skills/flutter-feature-scaffold/assets/templates/core/failure.dart.tmpl +24 -0
- package/skills/flutter-feature-scaffold/assets/templates/core/http_client.dart.tmpl +35 -0
- package/skills/flutter-feature-scaffold/assets/templates/cubit/cubit.dart.tmpl +29 -0
- package/skills/flutter-feature-scaffold/assets/templates/cubit/cubit_test.dart.tmpl +41 -0
- package/skills/flutter-feature-scaffold/assets/templates/cubit/view.dart.tmpl +52 -0
- package/skills/flutter-feature-scaffold/assets/templates/getx/api_client.dart.tmpl +21 -0
- package/skills/flutter-feature-scaffold/assets/templates/getx/binding.dart.tmpl +19 -0
- package/skills/flutter-feature-scaffold/assets/templates/getx/controller.dart.tmpl +34 -0
- package/skills/flutter-feature-scaffold/assets/templates/getx/controller_test.dart.tmpl +42 -0
- package/skills/flutter-feature-scaffold/assets/templates/getx/state.dart.tmpl +31 -0
- package/skills/flutter-feature-scaffold/assets/templates/getx/view.dart.tmpl +38 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/entity.dart.tmpl +9 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/notifier.dart.tmpl +25 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/notifier_test.dart.tmpl +56 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/repository.dart.tmpl +5 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/repository_impl.dart.tmpl +32 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/repository_impl_test.dart.tmpl +58 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/request.dart.tmpl +10 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/response.dart.tmpl +20 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/source.dart.tmpl +32 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/state.dart.tmpl +28 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/usecase.dart.tmpl +19 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/usecase_test.dart.tmpl +21 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/view.dart.tmpl +52 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/view_test.dart.tmpl +34 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvn/widget.dart.tmpl +19 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/api_client.dart.tmpl +31 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/api_model.dart.tmpl +20 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/command.dart.tmpl +66 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/repository.dart.tmpl +7 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/repository_impl.dart.tmpl +23 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/repository_impl_test.dart.tmpl +54 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/result.dart.tmpl +33 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/usecase.dart.tmpl +15 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/usecase_test.dart.tmpl +22 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/view.dart.tmpl +47 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/view_test.dart.tmpl +27 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/viewmodel.dart.tmpl +32 -0
- package/skills/flutter-feature-scaffold/assets/templates/mvvm/viewmodel_test.dart.tmpl +64 -0
- package/skills/flutter-feature-scaffold/assets/templates/provider/notifier.dart.tmpl +41 -0
- package/skills/flutter-feature-scaffold/assets/templates/provider/notifier_test.dart.tmpl +44 -0
- package/skills/flutter-feature-scaffold/assets/templates/provider/state.dart.tmpl +31 -0
- package/skills/flutter-feature-scaffold/assets/templates/provider/view.dart.tmpl +39 -0
- package/skills/flutter-feature-scaffold/assets/templates/provider/view_test.dart.tmpl +30 -0
- package/skills/flutter-feature-scaffold/assets/templates/riverpod/notifier.dart.tmpl +23 -0
- package/skills/flutter-feature-scaffold/assets/templates/riverpod/notifier_test.dart.tmpl +55 -0
- package/skills/flutter-feature-scaffold/assets/templates/riverpod/providers.dart.tmpl +24 -0
- package/skills/flutter-feature-scaffold/assets/templates/riverpod/view.dart.tmpl +45 -0
- package/skills/flutter-feature-scaffold/assets/templates/riverpod/view_test.dart.tmpl +31 -0
- package/skills/flutter-feature-scaffold/assets/templates/shared/list.dart.tmpl +21 -0
- package/skills/flutter-feature-scaffold/assets/templates/shared/model.dart.tmpl +27 -0
- package/skills/flutter-feature-scaffold/assets/templates/shared/repository.dart.tmpl +6 -0
- package/skills/flutter-feature-scaffold/assets/templates/shared/repository_impl.dart.tmpl +25 -0
- package/skills/flutter-feature-scaffold/assets/templates/shared/repository_impl_test.dart.tmpl +59 -0
- package/skills/flutter-feature-scaffold/assets/templates/shared/source.dart.tmpl +28 -0
- package/skills/flutter-feature-scaffold/references/profiles.md +145 -0
- package/skills/flutter-feature-scaffold/scripts/scaffold.py +1069 -0
- package/skills/flutter-firebase/SKILL.md +256 -0
- package/skills/flutter-firebase/references/firestore-data.md +178 -0
- package/skills/flutter-firebase/references/placement-by-architecture.md +309 -0
- package/skills/flutter-firebase/references/review.md +109 -0
- package/skills/flutter-firebase/references/rules.md +636 -0
- package/skills/flutter-firebase/references/security-rules-and-app-check.md +226 -0
- package/skills/flutter-firebase/references/setup-messaging-config.md +169 -0
- package/skills/flutter-firebase/references/testing-firebase.md +157 -0
- package/skills/flutter-firebase/scripts/check_firebase.py +2155 -0
- package/skills/flutter-forms/SKILL.md +191 -0
- package/skills/flutter-forms/references/multi-step-and-dirty-state.md +190 -0
- package/skills/flutter-forms/references/placement-by-architecture.md +326 -0
- package/skills/flutter-forms/references/review.md +88 -0
- package/skills/flutter-forms/references/rules.md +238 -0
- package/skills/flutter-forms/references/secure-inputs.md +256 -0
- package/skills/flutter-forms/references/validation-patterns.md +285 -0
- package/skills/flutter-forms/scripts/check_forms.py +1278 -0
- package/skills/flutter-i18n/SKILL.md +241 -0
- package/skills/flutter-i18n/references/formatting.md +174 -0
- package/skills/flutter-i18n/references/gen-l10n-and-arb.md +315 -0
- package/skills/flutter-i18n/references/placement-by-architecture.md +460 -0
- package/skills/flutter-i18n/references/review.md +93 -0
- package/skills/flutter-i18n/references/rtl-and-arabic.md +367 -0
- package/skills/flutter-i18n/scripts/check_i18n.py +1805 -0
- package/skills/flutter-navigation/SKILL.md +199 -0
- package/skills/flutter-navigation/references/deep-links-and-security.md +242 -0
- package/skills/flutter-navigation/references/go-router-patterns.md +361 -0
- package/skills/flutter-navigation/references/placement-by-architecture.md +414 -0
- package/skills/flutter-navigation/references/review.md +102 -0
- package/skills/flutter-navigation/references/rules.md +256 -0
- package/skills/flutter-navigation/scripts/check_navigation.py +1424 -0
- package/skills/flutter-networking/SKILL.md +202 -0
- package/skills/flutter-networking/references/client-setup.md +180 -0
- package/skills/flutter-networking/references/dtos-and-json.md +114 -0
- package/skills/flutter-networking/references/placement-by-architecture.md +147 -0
- package/skills/flutter-networking/references/requests.md +160 -0
- package/skills/flutter-networking/references/review.md +94 -0
- package/skills/flutter-networking/references/rules.md +487 -0
- package/skills/flutter-networking/references/testing-with-fakes.md +137 -0
- package/skills/flutter-networking/scripts/check_networking.py +1607 -0
- package/skills/flutter-performance/SKILL.md +219 -0
- package/skills/flutter-performance/references/diagnosing-jank.md +134 -0
- package/skills/flutter-performance/references/isolates.md +105 -0
- package/skills/flutter-performance/references/lists-images-painting.md +116 -0
- package/skills/flutter-performance/references/rebuild-scope.md +154 -0
- package/skills/flutter-performance/references/review.md +93 -0
- package/skills/flutter-performance/references/rules.md +400 -0
- package/skills/flutter-performance/scripts/check_performance.py +1360 -0
- package/skills/flutter-persistence/SKILL.md +198 -0
- package/skills/flutter-persistence/references/caching-and-offline.md +169 -0
- package/skills/flutter-persistence/references/choosing-storage.md +188 -0
- package/skills/flutter-persistence/references/migrations.md +201 -0
- package/skills/flutter-persistence/references/placement-by-architecture.md +232 -0
- package/skills/flutter-persistence/references/review.md +93 -0
- package/skills/flutter-persistence/references/rules.md +405 -0
- package/skills/flutter-persistence/scripts/check_persistence.py +1690 -0
- package/skills/flutter-platform-integration/SKILL.md +219 -0
- package/skills/flutter-platform-integration/references/channels-and-pigeon.md +194 -0
- package/skills/flutter-platform-integration/references/ffi.md +147 -0
- package/skills/flutter-platform-integration/references/permissions-and-isolates.md +124 -0
- package/skills/flutter-platform-integration/references/placement-by-architecture.md +102 -0
- package/skills/flutter-platform-integration/references/plugins-and-platform-views.md +129 -0
- package/skills/flutter-platform-integration/references/review.md +94 -0
- package/skills/flutter-platform-integration/references/rules.md +557 -0
- package/skills/flutter-platform-integration/references/testing-platform-code.md +125 -0
- package/skills/flutter-platform-integration/scripts/check_platform.py +1824 -0
- package/skills/flutter-release/SKILL.md +219 -0
- package/skills/flutter-release/references/ci-cd.md +156 -0
- package/skills/flutter-release/references/flavors-and-environments.md +127 -0
- package/skills/flutter-release/references/release-checklist.md +79 -0
- package/skills/flutter-release/references/review.md +91 -0
- package/skills/flutter-release/references/rules.md +417 -0
- package/skills/flutter-release/references/signing-and-versioning.md +113 -0
- package/skills/flutter-release/references/store-requirements.md +61 -0
- package/skills/flutter-release/scripts/check_release.py +1930 -0
- package/skills/flutter-secure-defaults/SKILL.md +270 -0
- package/skills/flutter-secure-defaults/references/network-and-auth.md +203 -0
- package/skills/flutter-secure-defaults/references/review.md +103 -0
- package/skills/flutter-secure-defaults/references/rules.md +452 -0
- package/skills/flutter-secure-defaults/references/secrets-and-config.md +136 -0
- package/skills/flutter-secure-defaults/references/secure-defaults-by-layer.md +474 -0
- package/skills/flutter-secure-defaults/references/secure-scaffold-checklist.md +147 -0
- package/skills/flutter-secure-defaults/references/storage-and-privacy.md +161 -0
- package/skills/flutter-secure-defaults/references/webview-and-links.md +153 -0
- package/skills/flutter-secure-defaults/scripts/check_secure_defaults.py +1571 -0
- package/skills/flutter-testing/SKILL.md +197 -0
- package/skills/flutter-testing/references/review.md +71 -0
- package/skills/flutter-testing/references/strategy-by-architecture.md +491 -0
- package/skills/flutter-testing/references/test-smells.md +475 -0
- package/skills/flutter-testing/references/widget-and-golden.md +337 -0
- package/skills/flutter-testing/scripts/test_gaps.py +1268 -0
- package/skills/flutter-ui-practices/SKILL.md +158 -0
- package/skills/flutter-ui-practices/references/flutter-ui.md +282 -0
- package/skills/flutter-ui-practices/references/review.md +89 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: flutter-feature-scaffold
|
|
3
|
+
description: Scaffold a new Flutter feature, screen, page or module in the architecture the project already uses - MVN (Riverpod codegen notifiers + use cases), MVVM (view models with Command/Result), Bloc, Cubit, GetX, Provider or plain Riverpod. It detects the pattern, copies the project's conventions (feature-first vs layer-first, Screen/Page/View, import style), dry-runs first and never overwrites, and its output is secure by default, with fake-based tests. Use it first, before writing any files, whenever someone asks to create, add, build, scaffold or generate a feature, module, page or new screen (settings, profile, checkout), says "generate the boilerplate" or "set up a feature in clean architecture/MVN/MVVM/bloc", or wants a new repository, notifier, bloc, cubit or view model with its layers, even if they never say "scaffold". For restructuring existing code, use flutter-architecture.
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
author: abdelrahman-abied
|
|
7
|
+
version: "1.7.2"
|
|
8
|
+
suite: flutter-pro-skills
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Flutter feature scaffold
|
|
12
|
+
|
|
13
|
+
Creates a new feature, with every layer, in **the architecture the project
|
|
14
|
+
already uses**, not the one you'd pick for a fresh app. It runs the
|
|
15
|
+
`flutter-architecture` checker, copies the conventions it finds, and produces
|
|
16
|
+
code that passes that checker with zero violations for the profile. It also
|
|
17
|
+
writes test skeletons that use fakes, and prints the commands that make the
|
|
18
|
+
code compile. Every generated file is idiomatic Dart 3: sealed states,
|
|
19
|
+
`final class` data types, `abstract interface class` contracts, const
|
|
20
|
+
constructors and `super.key`. It is also **secure by default** (see below):
|
|
21
|
+
the code passes the suite's security, error-handling and forms checkers with
|
|
22
|
+
zero findings, so it needs no hardening pass afterwards.
|
|
23
|
+
|
|
24
|
+
The script is `scripts/scaffold.py` (Python ≥3.8, stdlib only). It is the only
|
|
25
|
+
script in the suite that writes into a project, and it does so only with
|
|
26
|
+
`--write`. It never overwrites a file, never edits `pubspec.yaml`, and never runs
|
|
27
|
+
pub, build_runner or the analyzer itself.
|
|
28
|
+
|
|
29
|
+
## Workflow
|
|
30
|
+
|
|
31
|
+
1. **Detect.** Check for a declared architecture first, because it beats
|
|
32
|
+
inference: your agent's project instructions file (`AGENTS.md`, `CLAUDE.md`,
|
|
33
|
+
`GEMINI.md`, `.cursor/rules/…`, `.github/copilot-instructions.md`), the README
|
|
34
|
+
or ADRs. If one is declared, pass it as `--profile`. Otherwise `auto` runs
|
|
35
|
+
`../flutter-architecture/scripts/arch_check.py --json` for you. In a mixed
|
|
36
|
+
codebase, follow the pattern of the feature's neighbours or the declared
|
|
37
|
+
target, and don't add a third (flutter-architecture › `detect.md` §8).
|
|
38
|
+
2. **Dry run** (the default) and read the plan:
|
|
39
|
+
```bash
|
|
40
|
+
python3 -I <skill-dir>/scripts/scaffold.py <project-root> <feature_name> [--profile auto] [--clean] [--entity Name]
|
|
41
|
+
```
|
|
42
|
+
`== SCAFFOLD PLAN` shows the pattern and why it was chosen, the layout and
|
|
43
|
+
every inferred convention with its evidence. `== FILES` lists each file
|
|
44
|
+
with the classes and providers it declares (`+` new, `=` exists and will be
|
|
45
|
+
skipped). `== DEPENDENCIES` lists what's missing from pubspec.
|
|
46
|
+
3. **Decide, say it, and keep going.** Choose the feature name (snake_case,
|
|
47
|
+
named for the user-facing capability: `order_history`, not
|
|
48
|
+
`orders_screen`), the domain object name (`--entity Order` when it differs
|
|
49
|
+
from the feature), and whether to add use cases (`--clean`, or what the
|
|
50
|
+
project's neighbours do). State those choices in one line and go on to
|
|
51
|
+
step 4: the user already asked for the feature, the dry run shows the
|
|
52
|
+
plan, and `--write` never overwrites. Stop and ask **only** when the
|
|
53
|
+
answer would change the architecture and the project doesn't settle it:
|
|
54
|
+
confidence is `low`, the pattern looks wrong, or two patterns coexist
|
|
55
|
+
with no declared target. Then re-run with `--profile`. If nobody can
|
|
56
|
+
answer (a non-interactive or CI run), take the pattern of the feature's
|
|
57
|
+
neighbours, list the assumption in your final message, and write.
|
|
58
|
+
4. **Write**: add `--write`. Existing files are listed as `skipped … (exists, not
|
|
59
|
+
overwritten)`. If the feature folder already exists the script stops (exit 2)
|
|
60
|
+
unless you pass `--force-dir`, which adds only the missing files.
|
|
61
|
+
5. **Run the printed commands**, in order: `flutter pub add …` for missing
|
|
62
|
+
dependencies, `dart run build_runner build -d` for MVN and Riverpod (the
|
|
63
|
+
`*.g.dart` parts don't exist until then), then `dart analyze <paths>` and
|
|
64
|
+
`flutter test <paths>`. Expect zero analyzer errors or warnings and green
|
|
65
|
+
tests, because the templates are compile-checked against real projects.
|
|
66
|
+
6. **Wire it up** with the snippet under `== NEXT STEPS`: a route, plus
|
|
67
|
+
`ProviderScope`, `RepositoryProvider`, `ChangeNotifierProvider` or a `GetPage`
|
|
68
|
+
binding at the composition root, and the shared HTTP client created once
|
|
69
|
+
there (`createHttpClient()`, or `Get.put(ApiClient())` for GetX).
|
|
70
|
+
7. **Fill in the TODOs.** The script prints the count. They mark the parts only
|
|
71
|
+
you can write: the real fields of the entity, model and DTO (keep the
|
|
72
|
+
`fromJson` shape check); the endpoint path in the source; the https base URL
|
|
73
|
+
and the auth interceptor in the shared HTTP client; extra failure mapping in
|
|
74
|
+
the repository; and localized, user-facing error text. The wording follows
|
|
75
|
+
`flutter-secure-defaults` › `secure-scaffold-checklist.md` §10, so filling
|
|
76
|
+
them in keeps the defaults.
|
|
77
|
+
8. **Check once, at the end, with one command:**
|
|
78
|
+
`bash <skills-dir>/dart-flutter-review/scripts/review.sh <project-root> --diff HEAD --findings-only`.
|
|
79
|
+
It runs every checker in the suite and prints only what is left at low or
|
|
80
|
+
above (plus analyzer errors and warnings), each with its fix. Fix those and
|
|
81
|
+
run it again. Don't run the checkers one by one: each run adds a turn and
|
|
82
|
+
its whole output to the context, which is what makes a feature expensive.
|
|
83
|
+
|
|
84
|
+
### The screen's cross-cutting rules (no need to load the specialists)
|
|
85
|
+
|
|
86
|
+
The generated code already follows these. Keep them as you fill in the UI,
|
|
87
|
+
and you won't need to load the performance, design-system, accessibility,
|
|
88
|
+
adaptive-layout, networking or i18n skills to write a standard feature. Load
|
|
89
|
+
one only when the request is about that area itself, or when step 8 reports
|
|
90
|
+
a finding whose note you can't act on.
|
|
91
|
+
|
|
92
|
+
- **Lists:** `ListView.builder` / `GridView.builder` / slivers for data. For
|
|
93
|
+
pagination, fetch the next page from the logic holder behind an in-flight
|
|
94
|
+
guard (Bloc: a `droppable()` transformer).
|
|
95
|
+
- **Images:** set `cacheWidth` (or `memCacheWidth`) to the display size in
|
|
96
|
+
list items, and give each a `semanticLabel`, or `excludeFromSemantics` when
|
|
97
|
+
it is decorative.
|
|
98
|
+
- **Theme:** colours from `Theme.of(context).colorScheme`, text from
|
|
99
|
+
`textTheme`, no `Color(0x…)` or `fontSize:` literals. Dark mode then comes
|
|
100
|
+
for free.
|
|
101
|
+
- **Semantics:** a `tooltip` on every `IconButton`, `Semantics(button: true,
|
|
102
|
+
label:)` on custom tappables, targets of at least 48 dp, and no fixed height
|
|
103
|
+
around text.
|
|
104
|
+
- **Layout:** the width a widget gets (`LayoutBuilder`) or the window size
|
|
105
|
+
class picks one pane or two. Logic never reads the screen size, and keep the
|
|
106
|
+
selected item in the view or logic so it survives a resize.
|
|
107
|
+
- **Network:** one shared client with timeouts, injected into the remote
|
|
108
|
+
source. The repository maps errors to the project's `Failure`.
|
|
109
|
+
- **Text:** user-facing strings through the project's l10n (`AppLocalizations`),
|
|
110
|
+
never literals in widgets.
|
|
111
|
+
- **Tests (no need to load `flutter-testing`):** extend the generated tests to
|
|
112
|
+
cover what you filled in. Use fakes behind the contracts, not mocks, and no
|
|
113
|
+
real network or delays.
|
|
114
|
+
- **The repository** over a fake source: the success path, and each error
|
|
115
|
+
mapped to its `Failure`.
|
|
116
|
+
- **The logic holder** (notifier, view model or bloc): loading, then data,
|
|
117
|
+
empty or error. For pagination, test that the next page is appended, that
|
|
118
|
+
the in-flight guard drops a second request, and that a failed page keeps
|
|
119
|
+
the list.
|
|
120
|
+
- **The screen:** one widget test per state. For two panes, test both size
|
|
121
|
+
classes (`tester.view.physicalSize`, then `addTearDown(tester.view.reset)`).
|
|
122
|
+
- **Labels:** find controls by their label (`find.bySemanticsLabel`), so the
|
|
123
|
+
test also checks accessibility.
|
|
124
|
+
|
|
125
|
+
Exit codes: `0` means the plan was printed or the files were written. `2` means
|
|
126
|
+
a usage or environment error: no pubspec, an invalid name, an unsupported or
|
|
127
|
+
undetectable pattern, or a feature that already exists.
|
|
128
|
+
|
|
129
|
+
## CLI
|
|
130
|
+
|
|
131
|
+
```text
|
|
132
|
+
python3 -I scripts/scaffold.py <project-root> <feature_name>
|
|
133
|
+
[--profile auto|mvn|mvvm|bloc|cubit|getx|provider|riverpod]
|
|
134
|
+
[--clean] add domain/ entities + use cases where the pattern lacks them
|
|
135
|
+
[--entity <Name>] UpperCamel domain object name (default: from the feature)
|
|
136
|
+
[--write] create the files (never overwrites)
|
|
137
|
+
[--force-dir] allow adding files to an existing feature folder
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Feature names must be snake_case (`order_history` → `OrderHistory`). Dart
|
|
141
|
+
keywords and names that would collide with core types (`state`, `error`,
|
|
142
|
+
`widget`, `test`) are rejected with a suggestion.
|
|
143
|
+
|
|
144
|
+
## Profiles, conventions and what is left out
|
|
145
|
+
|
|
146
|
+
The dry run already lists every file it will write. For the per-profile file
|
|
147
|
+
lists, how conventions are inferred and what the scaffold deliberately does not
|
|
148
|
+
generate, read `references/profiles.md`.
|
|
149
|
+
|
|
150
|
+
## Secure by default
|
|
151
|
+
|
|
152
|
+
The templates follow the secure scaffold checklist, rules S-1 to S-33
|
|
153
|
+
(`../flutter-secure-defaults/references/secure-scaffold-checklist.md`), for
|
|
154
|
+
every profile, with and without `--clean`. Every generated feature guarantees:
|
|
155
|
+
|
|
156
|
+
- **One configured client, injected.** The source receives the app's HTTP
|
|
157
|
+
client (Dio, or GetConnect for GetX) through its constructor or provider. It
|
|
158
|
+
never builds `Dio()` or sets `BaseOptions`, so it can't skip the timeouts or
|
|
159
|
+
the auth interceptor. Paths are relative (`'/orders'`); the https base URL and
|
|
160
|
+
the timeouts live in the shared client (S-5, S-9, S-27, S-28).
|
|
161
|
+
- **No auth in features.** Nothing outside the shared client touches headers.
|
|
162
|
+
The auth interceptor is a TODO there, because the scheme is app-specific (S-6).
|
|
163
|
+
- **Validated JSON.** `fromJson(Object? json)` pattern-matches the shape and
|
|
164
|
+
throws `FormatException` on a mismatch. There are no `as` casts over
|
|
165
|
+
untrusted JSON, and the source checks that the payload is a list (S-14).
|
|
166
|
+
- **Typed failures.** The repository maps transport errors
|
|
167
|
+
(`DioException`, a GetConnect error response, `FormatException`) to a
|
|
168
|
+
`Failure` that carries no URL, headers or server text. MVVM returns it in a
|
|
169
|
+
`Result` (S-11).
|
|
170
|
+
- **User-safe errors.** Error state holds the `Failure`, never `e.toString()`.
|
|
171
|
+
The view maps it to fixed text in one `_failureMessage` function, ready for
|
|
172
|
+
localization, with a retry action (S-18, S-21, S-22, S-24).
|
|
173
|
+
- **Nothing logged.** No `print`, no logger and no HTTP logging interceptor.
|
|
174
|
+
The shared client says where debug-only logging may go (S-1, S-8, S-10, S-29).
|
|
175
|
+
- **Nothing risky by default.** No certificate overrides, `String.fromEnvironment`,
|
|
176
|
+
`http://` URLs, secrets, storage, WebViews, `launchUrl` or `HydratedBloc`
|
|
177
|
+
(S-2, S-4, S-13, S-20, S-26, S-30). Tests use obviously fake data and
|
|
178
|
+
check that a transport error becomes a typed failure (S-32, S-33).
|
|
179
|
+
|
|
180
|
+
The skill's tests enforce this: each profile and layout passes
|
|
181
|
+
`check_secure_defaults.py`, `check_errors.py` (nothing in the generated files),
|
|
182
|
+
`check_forms.py` and `arch_check.py` with zero findings, the generated files
|
|
183
|
+
get zero findings from `check_performance.py`, `check_persistence.py`,
|
|
184
|
+
`check_networking.py`, `check_firebase.py`, `check_platform.py`, `check_design_system.py`, `check_adaptive.py` and `check_accessibility.py` (clean by default: lazy
|
|
185
|
+
lists, theme colours, labelled buttons), plus greps for the
|
|
186
|
+
checklist rules the checkers can't see. If the project already configures a
|
|
187
|
+
client or declares a `Failure` type, the plan prints a `note:`. Inject that
|
|
188
|
+
client instead, so there's never a second, unauthenticated one (S-31).
|
|
189
|
+
|
|
190
|
+
## Notes
|
|
191
|
+
|
|
192
|
+
- A plain-Riverpod app with three or more `*Notifier extends _$X` classes looks
|
|
193
|
+
like MVN to the checker. Declare `riverpod` in the project instructions file
|
|
194
|
+
and pass `--profile riverpod`.
|
|
195
|
+
- Projects on `package:http` instead of Dio get a `note:`. The templates inject
|
|
196
|
+
Dio, so swap the client type in the source and the shared client.
|
|
197
|
+
- GetX, Bloc and Provider versions differ in small APIs. The templates target
|
|
198
|
+
current stable releases (flutter_bloc 9, get 4.7, provider 6, Riverpod 3).
|
|
199
|
+
On Riverpod 2.x, regenerate with the 2.x generator and check the provider
|
|
200
|
+
names it prints.
|
|
201
|
+
|
|
202
|
+
## Related skills
|
|
203
|
+
|
|
204
|
+
- `flutter-architecture`: detection, each pattern's rules, and the checker this
|
|
205
|
+
skill runs (if your agent doesn't auto-load skills, read
|
|
206
|
+
`../flutter-architecture/SKILL.md`). If it isn't installed, the script falls
|
|
207
|
+
back to a minimal built-in scan and says so in `profile source:`.
|
|
208
|
+
- `dart-naming`: role names per architecture, which the templates follow
|
|
209
|
+
(`../dart-naming/SKILL.md`, §12 of its reference).
|
|
210
|
+
- `flutter-testing`: grow the generated test skeletons
|
|
211
|
+
(`../flutter-testing/SKILL.md`).
|
|
212
|
+
- `flutter-error-handling`: the failure flow each profile follows, and how to
|
|
213
|
+
grow the `Failure` set (`../flutter-error-handling/SKILL.md`,
|
|
214
|
+
`../flutter-error-handling/references/error-flow-by-architecture.md`).
|
|
215
|
+
- `flutter-secure-defaults`: the checklist the templates follow, and the token
|
|
216
|
+
source and auth interceptor to add to the shared client
|
|
217
|
+
(`../flutter-secure-defaults/SKILL.md`).
|
|
218
|
+
- `dart-flutter-best-practices`, `flutter-ui-practices`: for the code you write
|
|
219
|
+
into the TODOs. `dart-flutter-review`: review the finished feature.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import 'package:equatable/equatable.dart';
|
|
2
|
+
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
3
|
+
|
|
4
|
+
import '{{import:failure}}';
|
|
5
|
+
import '{{import:entity}}';
|
|
6
|
+
import '{{import:dep}}';
|
|
7
|
+
|
|
8
|
+
part '{{feature}}_event.dart';
|
|
9
|
+
part '{{feature}}_state.dart';
|
|
10
|
+
|
|
11
|
+
/// Turns {{title_lc}} events into states. Receives its data only through
|
|
12
|
+
/// events and the constructor-injected dependency; it never knows other blocs.
|
|
13
|
+
class {{Logic}} extends Bloc<{{Event}}, {{State}}> {
|
|
14
|
+
{{#privnamed}} {{Logic}}({required this._{{dep}}}) : super(const {{Feature}}Initial()){{/privnamed}}{{^privnamed}} {{Logic}}({required {{Dep}} {{dep}}})
|
|
15
|
+
: _{{dep}} = {{dep}},
|
|
16
|
+
super(const {{Feature}}Initial()){{/privnamed}} {
|
|
17
|
+
on<{{Feature}}Started>(_onStarted);
|
|
18
|
+
on<{{Feature}}RefreshRequested>(_onRefreshRequested);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
final {{Dep}} _{{dep}};
|
|
22
|
+
|
|
23
|
+
Future<void> _onStarted(
|
|
24
|
+
{{Feature}}Started event,
|
|
25
|
+
Emitter<{{State}}> emit,
|
|
26
|
+
) =>
|
|
27
|
+
_load(emit);
|
|
28
|
+
|
|
29
|
+
Future<void> _onRefreshRequested(
|
|
30
|
+
{{Feature}}RefreshRequested event,
|
|
31
|
+
Emitter<{{State}}> emit,
|
|
32
|
+
) =>
|
|
33
|
+
_load(emit);
|
|
34
|
+
|
|
35
|
+
Future<void> _load(Emitter<{{State}}> emit) async {
|
|
36
|
+
emit(const {{Feature}}LoadInProgress());
|
|
37
|
+
try {
|
|
38
|
+
final List<{{Entity}}> items = await {{depCall}};
|
|
39
|
+
emit({{Feature}}LoadSuccess(items));
|
|
40
|
+
} on Failure catch (failure) {
|
|
41
|
+
emit({{Feature}}LoadFailure(failure));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import 'package:bloc_test/bloc_test.dart';
|
|
2
|
+
import 'package:flutter_test/flutter_test.dart';
|
|
3
|
+
|
|
4
|
+
import '{{import:failure}}';
|
|
5
|
+
import '{{import:entity}}';
|
|
6
|
+
import '{{import:repository}}';
|
|
7
|
+
{{#clean}}import '{{import:usecase}}';
|
|
8
|
+
{{/clean}}import '{{import:logic}}';
|
|
9
|
+
|
|
10
|
+
const _items = [{{Entity}}(id: '1', title: 'First')];
|
|
11
|
+
|
|
12
|
+
class Fake{{Repository}} implements {{Repository}} {
|
|
13
|
+
Fake{{Repository}}([this._failure]);
|
|
14
|
+
|
|
15
|
+
final Failure? _failure;
|
|
16
|
+
|
|
17
|
+
@override
|
|
18
|
+
Future<List<{{Entity}}>> fetch{{Feature}}List() async {
|
|
19
|
+
if (_failure case final failure?) throw failure;
|
|
20
|
+
return _items;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void main() {
|
|
25
|
+
blocTest<{{Logic}}, {{State}}>(
|
|
26
|
+
'emits [LoadInProgress, LoadSuccess] when {{Feature}}Started is added',
|
|
27
|
+
build: () => {{Logic}}({{dep}}: {{fakeDep}}),
|
|
28
|
+
act: (bloc) => bloc.add(const {{Feature}}Started()),
|
|
29
|
+
expect: () => const [{{Feature}}LoadInProgress(), {{Feature}}LoadSuccess(_items)],
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
blocTest<{{Logic}}, {{State}}>(
|
|
33
|
+
'emits [LoadInProgress, LoadFailure] with the typed failure when {{Feature}}Started fails',
|
|
34
|
+
build: () => {{Logic}}({{dep}}: {{failingDep}}),
|
|
35
|
+
act: (bloc) => bloc.add(const {{Feature}}Started()),
|
|
36
|
+
expect: () => const [
|
|
37
|
+
{{Feature}}LoadInProgress(),
|
|
38
|
+
{{Feature}}LoadFailure(NetworkFailure()),
|
|
39
|
+
],
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
part of '{{feature}}_bloc.dart';
|
|
2
|
+
|
|
3
|
+
/// Events are past-tense facts from the bloc's point of view.
|
|
4
|
+
sealed class {{Event}} extends Equatable {
|
|
5
|
+
const {{Event}}();
|
|
6
|
+
|
|
7
|
+
@override
|
|
8
|
+
List<Object> get props => const [];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/// The screen opened: load the {{title_lc}} for the first time.
|
|
12
|
+
final class {{Feature}}Started extends {{Event}} {
|
|
13
|
+
const {{Feature}}Started();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/// The user asked for fresh data (pull to refresh, retry).
|
|
17
|
+
final class {{Feature}}RefreshRequested extends {{Event}} {
|
|
18
|
+
const {{Feature}}RefreshRequested();
|
|
19
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
part of '{{partOf}}';
|
|
2
|
+
|
|
3
|
+
/// Exclusive states of the {{title_lc}} screen, with value equality so equal
|
|
4
|
+
/// states don't rebuild the UI.
|
|
5
|
+
sealed class {{State}} extends Equatable {
|
|
6
|
+
const {{State}}();
|
|
7
|
+
|
|
8
|
+
@override
|
|
9
|
+
List<Object> get props => const [];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
final class {{Feature}}Initial extends {{State}} {
|
|
13
|
+
const {{Feature}}Initial();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
final class {{Feature}}LoadInProgress extends {{State}} {
|
|
17
|
+
const {{Feature}}LoadInProgress();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
final class {{Feature}}LoadSuccess extends {{State}} {
|
|
21
|
+
const {{Feature}}LoadSuccess(this.items);
|
|
22
|
+
|
|
23
|
+
final List<{{Entity}}> items;
|
|
24
|
+
|
|
25
|
+
@override
|
|
26
|
+
List<Object> get props => [items];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// Holds a typed failure, never raw error text: the view picks the words.
|
|
30
|
+
final class {{Feature}}LoadFailure extends {{State}} {
|
|
31
|
+
const {{Feature}}LoadFailure(this.failure);
|
|
32
|
+
|
|
33
|
+
final Failure failure;
|
|
34
|
+
|
|
35
|
+
@override
|
|
36
|
+
List<Object> get props => [failure];
|
|
37
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import 'package:flutter/material.dart';
|
|
2
|
+
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
3
|
+
|
|
4
|
+
import '{{import:failure}}';
|
|
5
|
+
import '{{import:dep}}';
|
|
6
|
+
import '{{import:logic}}';
|
|
7
|
+
import '{{import:list}}';
|
|
8
|
+
|
|
9
|
+
/// Provides the [{{Logic}}] (which `BlocProvider` closes) and shows [{{InnerView}}].
|
|
10
|
+
class {{View}} extends StatelessWidget {
|
|
11
|
+
const {{View}}({super.key});
|
|
12
|
+
|
|
13
|
+
@override
|
|
14
|
+
Widget build(BuildContext context) {
|
|
15
|
+
return BlocProvider(
|
|
16
|
+
create: (context) => {{Logic}}({{dep}}: context.read<{{Dep}}>())
|
|
17
|
+
..add(const {{Feature}}Started()),
|
|
18
|
+
child: const {{InnerView}}(),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// Renders the {{title_lc}} states. One-time effects belong in a `BlocListener`.
|
|
24
|
+
class {{InnerView}} extends StatelessWidget {
|
|
25
|
+
const {{InnerView}}({super.key});
|
|
26
|
+
|
|
27
|
+
@override
|
|
28
|
+
Widget build(BuildContext context) {
|
|
29
|
+
return Scaffold(
|
|
30
|
+
appBar: AppBar(title: const Text('{{title}}')),
|
|
31
|
+
body: BlocBuilder<{{Logic}}, {{State}}>(
|
|
32
|
+
builder: (context, state) => switch (state) {
|
|
33
|
+
{{Feature}}Initial() ||
|
|
34
|
+
{{Feature}}LoadInProgress() => const Center(child: CircularProgressIndicator()),
|
|
35
|
+
{{Feature}}LoadFailure(:final failure) => Center(
|
|
36
|
+
child: TextButton.icon(
|
|
37
|
+
onPressed: () => context
|
|
38
|
+
.read<{{Logic}}>()
|
|
39
|
+
.add(const {{Feature}}RefreshRequested()),
|
|
40
|
+
icon: const Icon(Icons.refresh),
|
|
41
|
+
label: Text(_failureMessage(failure)),
|
|
42
|
+
),
|
|
43
|
+
),
|
|
44
|
+
{{Feature}}LoadSuccess(:final items) => {{ListWidget}}(items: items),
|
|
45
|
+
},
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// TODO: map the failure to a localized, user-safe message.
|
|
52
|
+
String _failureMessage(Failure failure) => switch (failure) {
|
|
53
|
+
NetworkFailure() => 'No connection. Tap to retry.',
|
|
54
|
+
_ => 'Could not load {{title_lc}}. Tap to retry.',
|
|
55
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import 'package:flutter/material.dart';
|
|
2
|
+
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
3
|
+
import 'package:flutter_test/flutter_test.dart';
|
|
4
|
+
|
|
5
|
+
import '{{import:entity}}';
|
|
6
|
+
import '{{import:repository}}';
|
|
7
|
+
{{#clean}}import '{{import:usecase}}';
|
|
8
|
+
{{/clean}}import '{{import:view}}';
|
|
9
|
+
|
|
10
|
+
class Fake{{Repository}} implements {{Repository}} {
|
|
11
|
+
@override
|
|
12
|
+
Future<List<{{Entity}}>> fetch{{Feature}}List() async =>
|
|
13
|
+
const [{{Entity}}(id: '1', title: 'First')];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
void main() {
|
|
17
|
+
testWidgets('{{View}} renders the loaded items', (tester) async {
|
|
18
|
+
await tester.pumpWidget(
|
|
19
|
+
RepositoryProvider<{{Dep}}>.value(
|
|
20
|
+
value: {{fakeDep}},
|
|
21
|
+
child: const MaterialApp(home: {{View}}()),
|
|
22
|
+
),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
await tester.pumpAndSettle();
|
|
26
|
+
|
|
27
|
+
expect(find.text('First'), findsOneWidget);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{{#dio}}import 'package:dio/dio.dart';
|
|
2
|
+
{{/dio}}{{#getconnect}}import 'package:get/get.dart';
|
|
3
|
+
{{/getconnect}}
|
|
4
|
+
{{#getconnect}}import '{{import:http_client}}';
|
|
5
|
+
{{/getconnect}}import '{{import:dto}}';
|
|
6
|
+
|
|
7
|
+
/// Raw access to the {{title_lc}} backend. A leaf: no UI state, no repositories.
|
|
8
|
+
abstract interface class {{Source}} {
|
|
9
|
+
Future<List<{{Feature}}Dto>> fetch{{Feature}}List();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
final class {{SourceImpl}} implements {{Source}} {
|
|
13
|
+
/// [_client] is the app's configured client: base URL, timeouts and auth.
|
|
14
|
+
const {{SourceImpl}}(this._client);
|
|
15
|
+
|
|
16
|
+
final {{Client}} _client;
|
|
17
|
+
|
|
18
|
+
@override
|
|
19
|
+
Future<List<{{Feature}}Dto>> fetch{{Feature}}List() async {
|
|
20
|
+
// TODO: call the backend through the injected client; auth headers come from its interceptor.
|
|
21
|
+
final response = await _client.get<Object?>('/{{feature}}');
|
|
22
|
+
{{#getconnect}} if (response.hasError) throw failureFromResponse(response);
|
|
23
|
+
{{/getconnect}} return switch (response.{{responseBody}}) {
|
|
24
|
+
final List<Object?> rows => [for (final row in rows) {{Feature}}Dto.fromJson(row)],
|
|
25
|
+
_ => throw const FormatException('Expected a list of {{title_lc}}'),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import 'package:flutter/foundation.dart';
|
|
2
|
+
|
|
3
|
+
import '{{import:entity}}';
|
|
4
|
+
|
|
5
|
+
/// Wire format of a {{title_lc}} item. Stays in `data/`; callers get entities.
|
|
6
|
+
// TODO: mirror the real payload, then map it in toEntity().
|
|
7
|
+
@immutable
|
|
8
|
+
final class {{Feature}}Dto {
|
|
9
|
+
const {{Feature}}Dto({required this.id, required this.title});
|
|
10
|
+
|
|
11
|
+
// TODO: validate the JSON shape here; throw FormatException on a mismatch.
|
|
12
|
+
factory {{Feature}}Dto.fromJson(Object? json) => switch (json) {
|
|
13
|
+
{'id': final String id, 'title': final String title} =>
|
|
14
|
+
{{Feature}}Dto(id: id, title: title),
|
|
15
|
+
_ => throw const FormatException('Unexpected {{title_lc}} payload'),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
final String id;
|
|
19
|
+
final String title;
|
|
20
|
+
|
|
21
|
+
Map<String, dynamic> toJson() => {'id': id, 'title': title};
|
|
22
|
+
|
|
23
|
+
{{Entity}} toEntity() => {{Entity}}(id: id, title: title);
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import 'package:meta/meta.dart';
|
|
2
|
+
|
|
3
|
+
/// A {{title_lc}} business object. Pure Dart: no JSON, no Flutter, no data imports.
|
|
4
|
+
// TODO: replace the placeholder fields with the real {{title_lc}} data.
|
|
5
|
+
@immutable
|
|
6
|
+
final class {{Entity}} {
|
|
7
|
+
const {{Entity}}({required this.id, required this.title});
|
|
8
|
+
|
|
9
|
+
final String id;
|
|
10
|
+
final String title;
|
|
11
|
+
|
|
12
|
+
@override
|
|
13
|
+
bool operator ==(Object other) =>
|
|
14
|
+
other is {{Entity}} && other.id == id && other.title == title;
|
|
15
|
+
|
|
16
|
+
@override
|
|
17
|
+
int get hashCode => Object.hash(id, title);
|
|
18
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{{#dio}}import 'package:dio/dio.dart';
|
|
2
|
+
|
|
3
|
+
{{/dio}}import '{{import:failure}}';
|
|
4
|
+
{{#dio}}import '{{import:http_client}}';
|
|
5
|
+
{{/dio}}import '{{import:entity}}';
|
|
6
|
+
import '{{import:repository}}';
|
|
7
|
+
import '{{import:source}}';
|
|
8
|
+
|
|
9
|
+
final class {{RepositoryImpl}} implements {{Repository}} {
|
|
10
|
+
const {{RepositoryImpl}}(this._source);
|
|
11
|
+
|
|
12
|
+
final {{Source}} _source;
|
|
13
|
+
|
|
14
|
+
@override
|
|
15
|
+
Future<List<{{Entity}}>> fetch{{Feature}}List() async {
|
|
16
|
+
// TODO: map transport exceptions to typed failures; never log request or response bodies.
|
|
17
|
+
try {
|
|
18
|
+
final dtos = await _source.fetch{{Feature}}List();
|
|
19
|
+
return [for (final dto in dtos) dto.toEntity()];
|
|
20
|
+
{{#dio}} } on DioException catch (error, stackTrace) {
|
|
21
|
+
Error.throwWithStackTrace(failureFromDio(error), stackTrace);
|
|
22
|
+
{{/dio}} } on FormatException catch (_, stackTrace) {
|
|
23
|
+
Error.throwWithStackTrace(const ParseFailure(), stackTrace);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{{#dio}}import 'package:dio/dio.dart';
|
|
2
|
+
{{/dio}}import 'package:flutter_test/flutter_test.dart';
|
|
3
|
+
|
|
4
|
+
import '{{import:failure}}';
|
|
5
|
+
import '{{import:entity}}';
|
|
6
|
+
import '{{import:dto}}';
|
|
7
|
+
import '{{import:repository_impl}}';
|
|
8
|
+
import '{{import:source}}';
|
|
9
|
+
|
|
10
|
+
class Fake{{Source}} implements {{Source}} {
|
|
11
|
+
Fake{{Source}}([this._error]);
|
|
12
|
+
|
|
13
|
+
final Exception? _error;
|
|
14
|
+
|
|
15
|
+
@override
|
|
16
|
+
Future<List<{{Feature}}Dto>> fetch{{Feature}}List() async {
|
|
17
|
+
if (_error case final error?) throw error;
|
|
18
|
+
return const [{{Feature}}Dto(id: '1', title: 'First')];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void main() {
|
|
23
|
+
test('{{RepositoryImpl}} maps DTOs to entities', () async {
|
|
24
|
+
final repository = {{RepositoryImpl}}(Fake{{Source}}());
|
|
25
|
+
|
|
26
|
+
final items = await repository.fetch{{Feature}}List();
|
|
27
|
+
|
|
28
|
+
expect(items, const [{{Entity}}(id: '1', title: 'First')]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('{{RepositoryImpl}} turns a transport error into a typed failure', () async {
|
|
32
|
+
{{#dio}} final source = Fake{{Source}}(
|
|
33
|
+
DioException(
|
|
34
|
+
requestOptions: RequestOptions(path: '/{{feature}}'),
|
|
35
|
+
type: DioExceptionType.connectionError,
|
|
36
|
+
),
|
|
37
|
+
);
|
|
38
|
+
{{/dio}}{{#getconnect}} // The source turns an error Response into a Failure (failureFromResponse).
|
|
39
|
+
final source = Fake{{Source}}(const NetworkFailure());
|
|
40
|
+
{{/getconnect}}
|
|
41
|
+
await expectLater(
|
|
42
|
+
{{RepositoryImpl}}(source).fetch{{Feature}}List(),
|
|
43
|
+
throwsA(isA<NetworkFailure>()),
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('{{RepositoryImpl}} maps a malformed payload to ParseFailure', () async {
|
|
48
|
+
final source = Fake{{Source}}(const FormatException('bad shape'));
|
|
49
|
+
|
|
50
|
+
await expectLater(
|
|
51
|
+
{{RepositoryImpl}}(source).fetch{{Feature}}List(),
|
|
52
|
+
throwsA(isA<ParseFailure>()),
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('{{Feature}}Dto.fromJson rejects a malformed payload', () {
|
|
57
|
+
expect(() => {{Feature}}Dto.fromJson({'id': 1}), throwsFormatException);
|
|
58
|
+
expect(() => {{Feature}}Dto.fromJson(null), throwsFormatException);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import '{{import:entity}}';
|
|
2
|
+
import '{{import:repository}}';
|
|
3
|
+
|
|
4
|
+
/// One intent: fetch the {{title_lc}} list.
|
|
5
|
+
// TODO: put the business rule here (filtering, combining repositories), or drop
|
|
6
|
+
// the use case if it only ever forwards to the repository.
|
|
7
|
+
final class {{UseCase}} {
|
|
8
|
+
const {{UseCase}}(this._repository);
|
|
9
|
+
|
|
10
|
+
final {{Repository}} _repository;
|
|
11
|
+
|
|
12
|
+
Future<List<{{Entity}}>> call() => _repository.fetch{{Feature}}List();
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import 'package:flutter_test/flutter_test.dart';
|
|
2
|
+
|
|
3
|
+
import '{{import:entity}}';
|
|
4
|
+
import '{{import:repository}}';
|
|
5
|
+
import '{{import:usecase}}';
|
|
6
|
+
|
|
7
|
+
class Fake{{Repository}} implements {{Repository}} {
|
|
8
|
+
@override
|
|
9
|
+
Future<List<{{Entity}}>> fetch{{Feature}}List() async =>
|
|
10
|
+
const [{{Entity}}(id: '1', title: 'First')];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
void main() {
|
|
14
|
+
test('{{UseCase}} returns the repository items', () async {
|
|
15
|
+
final useCase = {{UseCase}}(Fake{{Repository}}());
|
|
16
|
+
|
|
17
|
+
final items = await useCase();
|
|
18
|
+
|
|
19
|
+
expect(items, const [{{Entity}}(id: '1', title: 'First')]);
|
|
20
|
+
});
|
|
21
|
+
}
|