sdd-full 4.8.0 → 4.8.1

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.
Files changed (163) hide show
  1. package/bin.js +1 -1
  2. package/index.js +18 -12
  3. package/package.json +1 -1
  4. package/skills/VERSION.md +61 -175
  5. package/skills/design-planning/ai-coding-rules/SKILL.md +13 -5
  6. package/skills/design-planning/design-to-code/SKILL.md +14 -5
  7. package/skills/design-planning/enterprise-spec/SKILL.md +13 -5
  8. package/skills/design-planning/flutter-av/SKILL.md +16 -5
  9. package/skills/design-planning/flutter-map/SKILL.md +14 -5
  10. package/skills/design-planning/function-sdd/SKILL.md +13 -5
  11. package/skills/design-planning/global-overlay-stack-standard/SKILL.md +14 -4
  12. package/skills/design-planning/ui-motion-interaction-standard/SKILL.md +14 -4
  13. package/skills/design-planning/ui-sdd-specialized/SKILL.md +14 -5
  14. package/skills/development-execution/flutter-errors/SKILL.md +15 -5
  15. package/skills/quality-assurance/bdd-acceptance/SKILL.md +14 -5
  16. package/skills/quality-assurance/flutter-test/SKILL.md +16 -5
  17. package/skills/requirement-analysis/sdd/mock_sdd.md +156 -0
  18. package/skills/rules/project_rules.md +127 -538
  19. package/skills/rules/user_rules.md +263 -0
  20. package/skills/special-tools/env-check/SKILL.md +13 -5
  21. package/skills/special-tools/ios-full-auto-debug/SKILL.md +15 -5
  22. package/skills/flutter-skills/.github/dependabot.yaml +0 -15
  23. package/skills/flutter-skills/.github/workflows/dart_skills_lint_workflow.yaml +0 -68
  24. package/skills/flutter-skills/.github/workflows/skills_tool.yaml +0 -51
  25. package/skills/flutter-skills/CODE_OF_CONDUCT.md +0 -3
  26. package/skills/flutter-skills/CONTRIBUTING.md +0 -36
  27. package/skills/flutter-skills/LICENSE +0 -26
  28. package/skills/flutter-skills/README.md +0 -50
  29. package/skills/flutter-skills/pubspec.yaml +0 -9
  30. package/skills/flutter-skills/resources/flutter_skills.yaml +0 -434
  31. package/skills/flutter-skills/skills/flutter-add-integration-test/SKILL.md +0 -163
  32. package/skills/flutter-skills/skills/flutter-add-widget-preview/SKILL.md +0 -145
  33. package/skills/flutter-skills/skills/flutter-add-widget-test/SKILL.md +0 -154
  34. package/skills/flutter-skills/skills/flutter-apply-architecture-best-practices/SKILL.md +0 -162
  35. package/skills/flutter-skills/skills/flutter-build-responsive-layout/SKILL.md +0 -139
  36. package/skills/flutter-skills/skills/flutter-fix-layout-issues/SKILL.md +0 -130
  37. package/skills/flutter-skills/skills/flutter-implement-json-serialization/SKILL.md +0 -153
  38. package/skills/flutter-skills/skills/flutter-setup-declarative-routing/SKILL.md +0 -255
  39. package/skills/flutter-skills/skills/flutter-setup-localization/SKILL.md +0 -210
  40. package/skills/flutter-skills/skills/flutter-use-http-package/SKILL.md +0 -175
  41. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/add-dart-lint-validation-rule/SKILL.md +0 -196
  42. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-best-practices/SKILL.md +0 -65
  43. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-checks-migration/SKILL.md +0 -158
  44. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-cli-app-best-practices/SKILL.md +0 -168
  45. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-doc-validation/SKILL.md +0 -87
  46. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-long-lines/SKILL.md +0 -101
  47. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-matcher-best-practices/SKILL.md +0 -136
  48. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-modern-features/SKILL.md +0 -266
  49. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-package-maintenance/SKILL.md +0 -92
  50. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/SKILL.md +0 -92
  51. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/example/lib/src/calculator.dart +0 -7
  52. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/example/pubspec.yaml +0 -8
  53. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/example/test/calculator_test.dart +0 -11
  54. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/scripts/interpret_coverage.dart +0 -95
  55. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/scripts/pubspec.yaml +0 -6
  56. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/scripts/test/interpret_coverage_test.dart +0 -93
  57. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-fundamentals/SKILL.md +0 -173
  58. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/definition-of-done/SKILL.md +0 -27
  59. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/flutter_skills_ignore.json +0 -3
  60. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/grill-me/SKILL.md +0 -10
  61. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/ignore.json +0 -3
  62. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/test-driven-development/SKILL.md +0 -371
  63. package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/test-driven-development/testing-anti-patterns.md +0 -299
  64. package/skills/flutter-skills/tool/dart_skills_lint/AUTHORS +0 -7
  65. package/skills/flutter-skills/tool/dart_skills_lint/CHANGELOG.md +0 -12
  66. package/skills/flutter-skills/tool/dart_skills_lint/CONTRIBUTING.md +0 -51
  67. package/skills/flutter-skills/tool/dart_skills_lint/LICENSE +0 -27
  68. package/skills/flutter-skills/tool/dart_skills_lint/README.md +0 -203
  69. package/skills/flutter-skills/tool/dart_skills_lint/analysis_options.yaml +0 -296
  70. package/skills/flutter-skills/tool/dart_skills_lint/bench/README.md +0 -23
  71. package/skills/flutter-skills/tool/dart_skills_lint/bench/baseline_throughput.dart +0 -230
  72. package/skills/flutter-skills/tool/dart_skills_lint/bin/cli.dart +0 -10
  73. package/skills/flutter-skills/tool/dart_skills_lint/dart_skills_lint.yaml +0 -14
  74. package/skills/flutter-skills/tool/dart_skills_lint/documentation/feature_design_docs/PRODUCTION_READYNESS.md +0 -48
  75. package/skills/flutter-skills/tool/dart_skills_lint/documentation/feature_design_docs/completion_migration_plan.md +0 -99
  76. package/skills/flutter-skills/tool/dart_skills_lint/documentation/feature_design_docs/legacy_patterns_report.md +0 -110
  77. package/skills/flutter-skills/tool/dart_skills_lint/documentation/feature_design_docs/pub_vs_skill_report.md +0 -56
  78. package/skills/flutter-skills/tool/dart_skills_lint/documentation/knowledge/SPECIFICATION.md +0 -79
  79. package/skills/flutter-skills/tool/dart_skills_lint/documentation/knowledge/architecture_overview.md +0 -64
  80. package/skills/flutter-skills/tool/dart_skills_lint/lib/dart_skills_lint.dart +0 -11
  81. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/config_parser.dart +0 -156
  82. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/entry_point.dart +0 -354
  83. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/fixable_rule.dart +0 -20
  84. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/analysis_severity.dart +0 -15
  85. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/check_type.dart +0 -17
  86. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/ignore_entry.dart +0 -34
  87. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/ignore_entry.g.dart +0 -19
  88. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/skill_context.dart +0 -27
  89. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/skill_rule.dart +0 -27
  90. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/skills_ignores.dart +0 -26
  91. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/skills_ignores.g.dart +0 -24
  92. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/validation_error.dart +0 -31
  93. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rule_registry.dart +0 -79
  94. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/absolute_paths_rule.dart +0 -74
  95. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/description_length_rule.dart +0 -49
  96. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/disallowed_field_rule.dart +0 -61
  97. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/name_format_rule.dart +0 -167
  98. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/relative_paths_rule.dart +0 -72
  99. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/trailing_whitespace_rule.dart +0 -93
  100. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/valid_yaml_metadata_rule.dart +0 -74
  101. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/skills_ignores_storage.dart +0 -36
  102. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/validation_session.dart +0 -559
  103. package/skills/flutter-skills/tool/dart_skills_lint/lib/src/validator.dart +0 -238
  104. package/skills/flutter-skills/tool/dart_skills_lint/pubspec.yaml +0 -28
  105. package/skills/flutter-skills/tool/dart_skills_lint/skills/README.md +0 -10
  106. package/skills/flutter-skills/tool/dart_skills_lint/skills/dart-skills-lint-validation/SKILL.md +0 -195
  107. package/skills/flutter-skills/tool/dart_skills_lint/skills-lock.json +0 -75
  108. package/skills/flutter-skills/tool/dart_skills_lint/test/absolute_paths_test.dart +0 -167
  109. package/skills/flutter-skills/tool/dart_skills_lint/test/cli_integration_test.dart +0 -683
  110. package/skills/flutter-skills/tool/dart_skills_lint/test/config_file_test.dart +0 -292
  111. package/skills/flutter-skills/tool/dart_skills_lint/test/custom_rule_test.dart +0 -122
  112. package/skills/flutter-skills/tool/dart_skills_lint/test/directory_structure_test.dart +0 -163
  113. package/skills/flutter-skills/tool/dart_skills_lint/test/field_constraints_test.dart +0 -178
  114. package/skills/flutter-skills/tool/dart_skills_lint/test/fixer_test.dart +0 -172
  115. package/skills/flutter-skills/tool/dart_skills_lint/test/ignore_models_test.dart +0 -63
  116. package/skills/flutter-skills/tool/dart_skills_lint/test/metadata_validation_test.dart +0 -116
  117. package/skills/flutter-skills/tool/dart_skills_lint/test/relative_path_flag_test.dart +0 -70
  118. package/skills/flutter-skills/tool/dart_skills_lint/test/relative_paths_test.dart +0 -172
  119. package/skills/flutter-skills/tool/dart_skills_lint/test/resolve_rules_test.dart +0 -82
  120. package/skills/flutter-skills/tool/dart_skills_lint/test/rule_naming_test.dart +0 -29
  121. package/skills/flutter-skills/tool/dart_skills_lint/test/skills_ignores_storage_test.dart +0 -89
  122. package/skills/flutter-skills/tool/dart_skills_lint/test/test_utils.dart +0 -19
  123. package/skills/flutter-skills/tool/dart_skills_lint/test/trailing_whitespace_test.dart +0 -152
  124. package/skills/flutter-skills/tool/generator/README.md +0 -150
  125. package/skills/flutter-skills/tool/generator/analysis_options.yaml +0 -143
  126. package/skills/flutter-skills/tool/generator/bin/skills.dart +0 -73
  127. package/skills/flutter-skills/tool/generator/lib/src/commands/base_skill_command.dart +0 -87
  128. package/skills/flutter-skills/tool/generator/lib/src/commands/base_yaml_command.dart +0 -83
  129. package/skills/flutter-skills/tool/generator/lib/src/commands/generate_skill_command.dart +0 -92
  130. package/skills/flutter-skills/tool/generator/lib/src/commands/update_readme_command.dart +0 -150
  131. package/skills/flutter-skills/tool/generator/lib/src/commands/update_skill_command.dart +0 -97
  132. package/skills/flutter-skills/tool/generator/lib/src/commands/validate_skill_command.dart +0 -284
  133. package/skills/flutter-skills/tool/generator/lib/src/models/skill_params.dart +0 -41
  134. package/skills/flutter-skills/tool/generator/lib/src/services/gemini_service.dart +0 -310
  135. package/skills/flutter-skills/tool/generator/lib/src/services/markdown_converter.dart +0 -226
  136. package/skills/flutter-skills/tool/generator/lib/src/services/prompts.dart +0 -72
  137. package/skills/flutter-skills/tool/generator/lib/src/services/resource_fetcher_service.dart +0 -84
  138. package/skills/flutter-skills/tool/generator/lib/src/services/skill_instructions.dart +0 -30
  139. package/skills/flutter-skills/tool/generator/pubspec.yaml +0 -32
  140. package/skills/flutter-skills/tool/generator/test/commands/base_skill_command_test.dart +0 -131
  141. package/skills/flutter-skills/tool/generator/test/commands/validate_skills_input_test.dart +0 -263
  142. package/skills/flutter-skills/tool/generator/test/custom_skill_rules/last_modified_rule.dart +0 -32
  143. package/skills/flutter-skills/tool/generator/test/generate_skills_retry_test.dart +0 -105
  144. package/skills/flutter-skills/tool/generator/test/generate_skills_test.dart +0 -519
  145. package/skills/flutter-skills/tool/generator/test/lint_skills_test.dart +0 -34
  146. package/skills/flutter-skills/tool/generator/test/markdown_converter_test.dart +0 -103
  147. package/skills/flutter-skills/tool/generator/test/markdown_table_test.dart +0 -131
  148. package/skills/flutter-skills/tool/generator/test/models/skill_params_test.dart +0 -37
  149. package/skills/flutter-skills/tool/generator/test/services/gemini_service_test.dart +0 -291
  150. package/skills/flutter-skills/tool/generator/test/services/markdown_converter_test.dart +0 -156
  151. package/skills/flutter-skills/tool/generator/test/services/resource_fetcher_service_test.dart +0 -188
  152. package/skills/flutter-skills/tool/generator/test/update_skills_test.dart +0 -241
  153. package/skills/flutter-skills/tool/generator/test/validate_skills_test.dart +0 -728
  154. /package/skills/{.agents → flutter}/skills/flutter-add-integration-test/SKILL.md +0 -0
  155. /package/skills/{.agents → flutter}/skills/flutter-add-widget-preview/SKILL.md +0 -0
  156. /package/skills/{.agents → flutter}/skills/flutter-add-widget-test/SKILL.md +0 -0
  157. /package/skills/{.agents → flutter}/skills/flutter-apply-architecture-best-practices/SKILL.md +0 -0
  158. /package/skills/{.agents → flutter}/skills/flutter-build-responsive-layout/SKILL.md +0 -0
  159. /package/skills/{.agents → flutter}/skills/flutter-fix-layout-issues/SKILL.md +0 -0
  160. /package/skills/{.agents → flutter}/skills/flutter-implement-json-serialization/SKILL.md +0 -0
  161. /package/skills/{.agents → flutter}/skills/flutter-setup-declarative-routing/SKILL.md +0 -0
  162. /package/skills/{.agents → flutter}/skills/flutter-setup-localization/SKILL.md +0 -0
  163. /package/skills/{.agents → flutter}/skills/flutter-use-http-package/SKILL.md +0 -0
@@ -1,130 +0,0 @@
1
- ---
2
- name: flutter-fix-layout-issues
3
- description: Fixes Flutter layout errors (overflows, unbounded constraints) using Dart and Flutter MCP tools. Use when addressing "RenderFlex overflowed", "Vertical viewport was given unbounded height", or similar layout issues.
4
- metadata:
5
- model: models/gemini-3.1-pro-preview
6
- last_modified: Tue, 21 Apr 2026 19:45:59 GMT
7
- ---
8
- # Resolving Flutter Layout Errors
9
-
10
- ## Contents
11
- - [Constraint Violation Diagnostics](#constraint-violation-diagnostics)
12
- - [Layout Error Resolution Workflow](#layout-error-resolution-workflow)
13
- - [Examples](#examples)
14
-
15
- ## Constraint Violation Diagnostics
16
-
17
- Flutter layout operates on a strict rule: **Constraints go down. Sizes go up. Parent sets position.** Layout errors occur when this negotiation fails, typically due to unbounded constraints or unconstrained children.
18
-
19
- Diagnose layout failures using the following error signatures:
20
-
21
- * **"Vertical viewport was given unbounded height"**: Triggered when a scrollable widget (`ListView`, `GridView`) is placed inside an unconstrained vertical parent (`Column`). The parent provides infinite height, and the child attempts to expand infinitely.
22
- * **"An InputDecorator...cannot have an unbounded width"**: Triggered when a `TextField` or `TextFormField` is placed inside an unconstrained horizontal parent (`Row`). The text field attempts to determine its width based on infinite available space.
23
- * **"RenderFlex overflowed"**: Triggered when a child of a `Row` or `Column` requests a size larger than the parent's allocated constraints. Visually indicated by yellow and black warning stripes.
24
- * **"Incorrect use of ParentData widget"**: Triggered when a `ParentDataWidget` is not a direct descendant of its required ancestor. (e.g., `Expanded` outside a `Flex`, `Positioned` outside a `Stack`).
25
- * **"RenderBox was not laid out"**: A cascading side-effect error. Ignore this and look further up the stack trace for the primary constraint violation (usually an unbounded height/width error).
26
-
27
- ## Layout Error Resolution Workflow
28
-
29
- Copy and use this checklist to systematically resolve layout constraint violations.
30
-
31
- ### Task Progress
32
- - [ ] Run the application in debug mode to capture the exact layout exception in the console.
33
- - [ ] Identify the primary error message (ignore cascading "RenderBox was not laid out" errors).
34
- - [ ] Apply the conditional fix based on the specific error type:
35
- - **If "Vertical viewport was given unbounded height"**: Wrap the scrollable child (`ListView`, `GridView`) in an `Expanded` widget to consume remaining space, or wrap it in a `SizedBox` to provide an absolute height constraint.
36
- - **If "An InputDecorator...cannot have an unbounded width"**: Wrap the `TextField` or `TextFormField` in an `Expanded` or `Flexible` widget.
37
- - **If "RenderFlex overflowed"**: Constrain the overflowing child by wrapping it in an `Expanded` widget (to force it to fit) or a `Flexible` widget (to allow it to be smaller than the allocated space).
38
- - **If "Incorrect use of ParentData widget"**: Move the `ParentDataWidget` to be a direct child of its required parent. Ensure `Expanded`/`Flexible` are direct children of `Row`/`Column`/`Flex`. Ensure `Positioned` is a direct child of `Stack`.
39
- - [ ] Execute Flutter hot reload.
40
- - [ ] Run validator -> review errors -> fix: Inspect the UI to verify the red/grey error screen or yellow/black overflow stripes are resolved. If new layout errors appear, repeat the workflow.
41
-
42
- ## Examples
43
-
44
- ### Fixing Unbounded Height (ListView in Column)
45
-
46
- **Input (Error State):**
47
- ```dart
48
- // Throws "Vertical viewport was given unbounded height"
49
- Column(
50
- children: <Widget>[
51
- const Text('Header'),
52
- ListView(
53
- children: const <Widget>[
54
- ListTile(title: Text('Item 1')),
55
- ListTile(title: Text('Item 2')),
56
- ],
57
- ),
58
- ],
59
- )
60
- ```
61
-
62
- **Output (Resolved State):**
63
- ```dart
64
- // Wrap ListView in Expanded to constrain its height to the remaining Column space
65
- Column(
66
- children: <Widget>[
67
- const Text('Header'),
68
- Expanded(
69
- child: ListView(
70
- children: const <Widget>[
71
- ListTile(title: Text('Item 1')),
72
- ListTile(title: Text('Item 2')),
73
- ],
74
- ),
75
- ),
76
- ],
77
- )
78
- ```
79
-
80
- ### Fixing Unbounded Width (TextField in Row)
81
-
82
- **Input (Error State):**
83
- ```dart
84
- // Throws "An InputDecorator...cannot have an unbounded width"
85
- Row(
86
- children: [
87
- const Icon(Icons.search),
88
- TextField(),
89
- ],
90
- )
91
- ```
92
-
93
- **Output (Resolved State):**
94
- ```dart
95
- // Wrap TextField in Expanded to constrain its width to the remaining Row space
96
- Row(
97
- children: [
98
- const Icon(Icons.search),
99
- Expanded(
100
- child: TextField(),
101
- ),
102
- ],
103
- )
104
- ```
105
-
106
- ### Fixing RenderFlex Overflow
107
-
108
- **Input (Error State):**
109
- ```dart
110
- // Throws "A RenderFlex overflowed by X pixels on the right"
111
- Row(
112
- children: [
113
- const Icon(Icons.info),
114
- const Text('This is a very long text string that will definitely overflow the available screen width and cause a RenderFlex error.'),
115
- ],
116
- )
117
- ```
118
-
119
- **Output (Resolved State):**
120
- ```dart
121
- // Wrap the Text widget in Expanded to force it to wrap within the available constraints
122
- Row(
123
- children: [
124
- const Icon(Icons.info),
125
- Expanded(
126
- child: const Text('This is a very long text string that will definitely overflow the available screen width and cause a RenderFlex error.'),
127
- ),
128
- ],
129
- )
130
- ```
@@ -1,153 +0,0 @@
1
- ---
2
- name: flutter-implement-json-serialization
3
- description: Create model classes with `fromJson` and `toJson` methods using `dart:convert`. Use when manually mapping JSON keys to class properties for simple data structures.
4
- metadata:
5
- model: models/gemini-3.1-pro-preview
6
- last_modified: Tue, 21 Apr 2026 21:44:50 GMT
7
- ---
8
- # Serializing JSON Manually in Flutter
9
-
10
- ## Contents
11
- - [Core Guidelines](#core-guidelines)
12
- - [Workflow: Implementing a Serializable Model](#workflow-implementing-a-serializable-model)
13
- - [Workflow: Fetching and Parsing JSON](#workflow-fetching-and-parsing-json)
14
- - [Examples](#examples)
15
-
16
- ## Core Guidelines
17
-
18
- - **Import `dart:convert`**: Utilize Flutter's built-in `dart:convert` library for manual JSON encoding (`jsonEncode`) and decoding (`jsonDecode`).
19
- - **Enforce Type Safety**: Always cast the `dynamic` result of `jsonDecode()` to the expected type, typically `Map<String, dynamic>` for objects or `List<dynamic>` for arrays.
20
- - **Encapsulate Serialization Logic**: Define plain model classes containing properties corresponding to the JSON structure. Implement a `fromJson` factory constructor and a `toJson` method within the model.
21
- - **Handle Background Parsing**: If parsing large JSON documents (execution time > 16ms), offload the parsing logic to a separate isolate using Flutter's `compute()` function to prevent UI jank.
22
- - **Throw Exceptions on Failure**: When handling HTTP responses, throw an exception if the status code is not successful (e.g., not 200 OK or 201 Created). Do not return `null`.
23
-
24
- ## Workflow: Implementing a Serializable Model
25
-
26
- Use this checklist to implement manual JSON serialization for a data model.
27
-
28
- **Task Progress:**
29
- - [ ] Define the plain model class with `final` properties.
30
- - [ ] Implement the `factory Model.fromJson(Map<String, dynamic> json)` constructor.
31
- - [ ] Implement the `Map<String, dynamic> toJson()` method.
32
- - [ ] Write unit tests for both serialization methods.
33
- - [ ] Run validator -> review type mismatch errors -> fix casting logic.
34
-
35
- 1. **Define the Model**: Create a class with properties matching the JSON keys.
36
- 2. **Implement `fromJson`**: Extract values from the `Map` and cast them to the appropriate Dart types. Use pattern matching or explicit casting.
37
- 3. **Implement `toJson`**: Return a `Map<String, dynamic>` mapping the class properties back to their JSON string keys.
38
- 4. **Validate**: Execute unit tests to ensure type safety, autocompletion, and compile-time exception handling function correctly.
39
-
40
- ## Workflow: Fetching and Parsing JSON
41
-
42
- Use this conditional workflow when retrieving and parsing JSON from a network request.
43
-
44
- **Task Progress:**
45
- - [ ] Execute the HTTP request.
46
- - [ ] Validate the response status code.
47
- - [ ] Determine parsing strategy (Synchronous vs. Isolate).
48
- - [ ] Decode and map the JSON to the model.
49
-
50
- 1. **Execute Request**: Use the `http` package to perform the network call.
51
- 2. **Validate Response**:
52
- - If `response.statusCode == 200` (or 201 for POST), proceed to parsing.
53
- - If the status code indicates failure, throw an `Exception`.
54
- 3. **Determine Parsing Strategy**:
55
- - If parsing a **small payload** (e.g., a single object), parse synchronously on the main thread.
56
- - If parsing a **large payload** (e.g., an array of thousands of objects), use `compute(parseFunction, response.body)` to parse in a background isolate.
57
- 4. **Decode and Map**: Pass the decoded JSON to your model's `fromJson` constructor.
58
-
59
- ## Examples
60
-
61
- ### High-Fidelity Model Implementation
62
-
63
- ```dart
64
- import 'dart:convert';
65
-
66
- class User {
67
- final int id;
68
- final String name;
69
- final String email;
70
-
71
- const User({
72
- required this.id,
73
- required this.name,
74
- required this.email,
75
- });
76
-
77
- // Factory constructor for deserialization
78
- factory User.fromJson(Map<String, dynamic> json) {
79
- return switch (json) {
80
- {
81
- 'id': int id,
82
- 'name': String name,
83
- 'email': String email,
84
- } =>
85
- User(
86
- id: id,
87
- name: name,
88
- email: email,
89
- ),
90
- _ => throw const FormatException('Failed to load User.'),
91
- };
92
- }
93
-
94
- // Method for serialization
95
- Map<String, dynamic> toJson() {
96
- return {
97
- 'id': id,
98
- 'name': name,
99
- 'email': email,
100
- };
101
- }
102
- }
103
- ```
104
-
105
- ### Synchronous Parsing (Small Payload)
106
-
107
- ```dart
108
- import 'dart:convert';
109
- import 'package:http/http.dart' as http;
110
-
111
- Future<User> fetchUser(http.Client client, int userId) async {
112
- final response = await client.get(
113
- Uri.parse('https://api.example.com/users/$userId'),
114
- headers: {'Accept': 'application/json'},
115
- );
116
-
117
- if (response.statusCode == 200) {
118
- // Decode returns dynamic, cast to Map<String, dynamic>
119
- final Map<String, dynamic> jsonMap = jsonDecode(response.body) as Map<String, dynamic>;
120
- return User.fromJson(jsonMap);
121
- } else {
122
- throw Exception('Failed to load user');
123
- }
124
- }
125
- ```
126
-
127
- ### Background Parsing (Large Payload)
128
-
129
- ```dart
130
- import 'dart:convert';
131
- import 'package:flutter/foundation.dart';
132
- import 'package:http/http.dart' as http;
133
-
134
- // Top-level function required for compute()
135
- List<User> parseUsers(String responseBody) {
136
- final parsed = (jsonDecode(responseBody) as List<dynamic>).cast<Map<String, dynamic>>();
137
- return parsed.map<User>((json) => User.fromJson(json)).toList();
138
- }
139
-
140
- Future<List<User>> fetchUsers(http.Client client) async {
141
- final response = await client.get(
142
- Uri.parse('https://api.example.com/users'),
143
- headers: {'Accept': 'application/json'},
144
- );
145
-
146
- if (response.statusCode == 200) {
147
- // Offload expensive parsing to a background isolate
148
- return compute(parseUsers, response.body);
149
- } else {
150
- throw Exception('Failed to load users');
151
- }
152
- }
153
- ```
@@ -1,255 +0,0 @@
1
- ---
2
- name: flutter-setup-declarative-routing
3
- description: Configure `MaterialApp.router` using a package like `go_router` for advanced URL-based navigation. Use when developing web applications or mobile apps that require specific deep linking and browser history support.
4
- metadata:
5
- model: models/gemini-3.1-pro-preview
6
- last_modified: Tue, 21 Apr 2026 21:08:03 GMT
7
- ---
8
- # Implementing Routing and Deep Linking
9
-
10
- ## Contents
11
- - [Core Concepts](#core-concepts)
12
- - [Workflow: Initializing the Application and Router](#workflow-initializing-the-application-and-router)
13
- - [Workflow: Configuring Platform Deep Linking](#workflow-configuring-platform-deep-linking)
14
- - [Workflow: Implementing Nested Navigation](#workflow-implementing-nested-navigation)
15
- - [Examples](#examples)
16
-
17
- ## Core Concepts
18
-
19
- Use the `go_router` package for declarative routing in Flutter. It provides a robust API for complex routing scenarios, deep linking, and nested navigation.
20
-
21
- - **GoRouter**: The central configuration object defining the application's route tree.
22
- - **GoRoute**: A standard route mapping a URL path to a Flutter screen.
23
- - **ShellRoute / StatefulShellRoute**: Wraps child routes in a persistent UI shell (e.g., a `BottomNavigationBar`). `StatefulShellRoute` maintains the state of parallel navigation branches.
24
- - **Path URL Strategy**: Removes the default `#` fragment from web URLs, essential for clean deep linking across platforms.
25
-
26
- ## Workflow: Initializing the Application and Router
27
-
28
- Follow this workflow to bootstrap a new Flutter application with `go_router` and configure the root routing mechanism.
29
-
30
- ### Task Progress
31
- - [ ] Create the Flutter application.
32
- - [ ] Add the `go_router` dependency.
33
- - [ ] Configure the URL strategy for web/deep linking.
34
- - [ ] Implement the `GoRouter` configuration.
35
- - [ ] Bind the router to `MaterialApp.router`.
36
-
37
- ### 1. Scaffold the Application
38
- Run the following commands to create the app and add the required routing package:
39
- ```bash
40
- flutter create <app-name>
41
- cd <app-name>
42
- flutter pub add go_router
43
- ```
44
-
45
- ### 2. Configure the Router
46
- Define a top-level `GoRouter` instance. Handle authentication or state-based routing using the `redirect` parameter.
47
-
48
- ```dart
49
- import 'package:flutter/material.dart';
50
- import 'package:go_router/go_router.dart';
51
- import 'package:flutter_web_plugins/url_strategy.dart';
52
-
53
- void main() {
54
- // Use path URL strategy to remove the '#' from web URLs
55
- usePathUrlStrategy();
56
- runApp(const MyApp());
57
- }
58
-
59
- final GoRouter _router = GoRouter(
60
- initialLocation: '/',
61
- routes: [
62
- GoRoute(
63
- path: '/',
64
- builder: (context, state) => const HomeScreen(),
65
- routes: [
66
- GoRoute(
67
- path: 'details/:id',
68
- builder: (context, state) => DetailsScreen(id: state.pathParameters['id']!),
69
- ),
70
- ],
71
- ),
72
- ],
73
- errorBuilder: (context, state) => ErrorScreen(error: state.error),
74
- );
75
-
76
- class MyApp extends StatelessWidget {
77
- const MyApp({super.key});
78
-
79
- @override
80
- Widget build(BuildContext context) {
81
- return MaterialApp.router(
82
- routerConfig: _router,
83
- title: 'Routing App',
84
- );
85
- }
86
- }
87
- ```
88
-
89
- ## Workflow: Configuring Platform Deep Linking
90
-
91
- Configure the native platforms to intercept specific URLs and route them into the Flutter application.
92
-
93
- ### Task Progress
94
- - [ ] Determine target platforms (iOS, Android, or both).
95
- - [ ] Apply conditional configuration for Android (Manifest + Asset Links).
96
- - [ ] Apply conditional configuration for iOS (Plist + Entitlements + AASA).
97
- - [ ] Run validator -> review errors -> fix.
98
-
99
- ### If configuring for Android:
100
- 1. **Modify `AndroidManifest.xml`**: Add the intent filter inside the `<activity>` tag for `.MainActivity`.
101
- ```xml
102
- <intent-filter android:autoVerify="true">
103
- <action android:name="android.intent.action.VIEW" />
104
- <category android:name="android.intent.category.DEFAULT" />
105
- <category android:name="android.intent.category.BROWSABLE" />
106
- <data android:scheme="http" android:host="yourdomain.com" />
107
- <data android:scheme="https" />
108
- </intent-filter>
109
- ```
110
- 2. **Host `assetlinks.json`**: Serve the following JSON at `https://yourdomain.com/.well-known/assetlinks.json`.
111
- ```json
112
- [{
113
- "relation": ["delegate_permission/common.handle_all_urls"],
114
- "target": {
115
- "namespace": "android_app",
116
- "package_name": "com.yourcompany.yourapp",
117
- "sha256_cert_fingerprints": ["YOUR_SHA256_FINGERPRINT"]
118
- }
119
- }]
120
- ```
121
-
122
- ### If configuring for iOS:
123
- 1. **Modify `Info.plist`**: Opt-in to Flutter's default deep link handler.
124
- *Note: If using a third-party deep linking plugin (e.g., `app_links`), set this to `NO` to prevent conflicts.*
125
- ```xml
126
- <key>FlutterDeepLinkingEnabled</key>
127
- <true/>
128
- ```
129
- 2. **Modify `Runner.entitlements`**: Add the associated domain.
130
- ```xml
131
- <key>com.apple.developer.associated-domains</key>
132
- <array>
133
- <string>applinks:yourdomain.com</string>
134
- </array>
135
- ```
136
- 3. **Host `apple-app-site-association`**: Serve the following JSON (without a `.json` extension) at `https://yourdomain.com/.well-known/apple-app-site-association`.
137
- ```json
138
- {
139
- "applinks": {
140
- "apps": [],
141
- "details": [{
142
- "appIDs": ["TEAM_ID.com.yourcompany.yourapp"],
143
- "paths": ["*"],
144
- "components": [{"/": "/*"}]
145
- }]
146
- }
147
- }
148
- ```
149
-
150
- ### Validation Loop
151
- Run validator -> review errors -> fix.
152
- - **Android**: Test using ADB.
153
- ```bash
154
- adb shell 'am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://yourdomain.com/details/123"' com.yourcompany.yourapp
155
- ```
156
- - **iOS**: Test using `xcrun` on a booted simulator.
157
- ```bash
158
- xcrun simctl openurl booted https://yourdomain.com/details/123
159
- ```
160
-
161
- ## Workflow: Implementing Nested Navigation
162
-
163
- Use `StatefulShellRoute` to implement persistent UI shells (like a bottom navigation bar) that maintain the state of their child routes.
164
-
165
- ### Task Progress
166
- - [ ] Define `StatefulShellRoute.indexedStack` in the `GoRouter` configuration.
167
- - [ ] Create `StatefulShellBranch` instances for each navigation tab.
168
- - [ ] Implement the shell widget using `StatefulNavigationShell`.
169
-
170
- ```dart
171
- final GoRouter _router = GoRouter(
172
- initialLocation: '/home',
173
- routes: [
174
- StatefulShellRoute.indexedStack(
175
- builder: (context, state, navigationShell) {
176
- return ScaffoldWithNavBar(navigationShell: navigationShell);
177
- },
178
- branches: [
179
- StatefulShellBranch(
180
- routes: [
181
- GoRoute(
182
- path: '/home',
183
- builder: (context, state) => const HomeScreen(),
184
- ),
185
- ],
186
- ),
187
- StatefulShellBranch(
188
- routes: [
189
- GoRoute(
190
- path: '/settings',
191
- builder: (context, state) => const SettingsScreen(),
192
- ),
193
- ],
194
- ),
195
- ],
196
- ),
197
- ],
198
- );
199
- ```
200
-
201
- ## Examples
202
-
203
- ### High-Fidelity Shell Widget Implementation
204
- Implement the UI shell that consumes the `StatefulNavigationShell` to handle branch switching.
205
-
206
- ```dart
207
- class ScaffoldWithNavBar extends StatelessWidget {
208
- const ScaffoldWithNavBar({
209
- required this.navigationShell,
210
- super.key,
211
- });
212
-
213
- final StatefulNavigationShell navigationShell;
214
-
215
- void _goBranch(int index) {
216
- navigationShell.goBranch(
217
- index,
218
- // Support navigating to the initial location when tapping the active tab.
219
- initialLocation: index == navigationShell.currentIndex,
220
- );
221
- }
222
-
223
- @override
224
- Widget build(BuildContext context) {
225
- return Scaffold(
226
- body: navigationShell,
227
- bottomNavigationBar: NavigationBar(
228
- selectedIndex: navigationShell.currentIndex,
229
- onDestinationSelected: _goBranch,
230
- destinations: const [
231
- NavigationDestination(icon: Icon(Icons.home), label: 'Home'),
232
- NavigationDestination(icon: Icon(Icons.settings), label: 'Settings'),
233
- ],
234
- ),
235
- );
236
- }
237
- }
238
- ```
239
-
240
- ### Programmatic Navigation
241
- Use the `context.go()` and `context.push()` extension methods provided by `go_router`.
242
-
243
- ```dart
244
- // Replaces the current route stack with the target route (Declarative)
245
- context.go('/details/123');
246
-
247
- // Pushes the target route onto the existing stack (Imperative)
248
- context.push('/details/123');
249
-
250
- // Navigates using a named route and path parameters
251
- context.goNamed('details', pathParameters: {'id': '123'});
252
-
253
- // Pops the current route
254
- context.pop();
255
- ```