sdd-full 4.6.1 → 4.8.0
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/bin.js +1 -1
- package/package.json +1 -1
- package/skills/.agents/skills/flutter-add-integration-test/SKILL.md +165 -0
- package/skills/.agents/skills/flutter-add-widget-preview/SKILL.md +147 -0
- package/skills/.agents/skills/flutter-add-widget-test/SKILL.md +156 -0
- package/skills/.agents/skills/flutter-apply-architecture-best-practices/SKILL.md +164 -0
- package/skills/.agents/skills/flutter-build-responsive-layout/SKILL.md +141 -0
- package/skills/.agents/skills/flutter-fix-layout-issues/SKILL.md +132 -0
- package/skills/.agents/skills/flutter-implement-json-serialization/SKILL.md +155 -0
- package/skills/.agents/skills/flutter-setup-declarative-routing/SKILL.md +257 -0
- package/skills/.agents/skills/flutter-setup-localization/SKILL.md +212 -0
- package/skills/.agents/skills/flutter-use-http-package/SKILL.md +177 -0
- package/skills/VERSION.md +186 -62
- package/skills/design-planning/ai-coding-rules/SKILL.md +5 -13
- package/skills/design-planning/design-to-code/SKILL.md +5 -14
- package/skills/design-planning/enterprise-spec/SKILL.md +5 -13
- package/skills/design-planning/flutter-av/SKILL.md +5 -16
- package/skills/design-planning/flutter-map/SKILL.md +5 -14
- package/skills/design-planning/function-sdd/SKILL.md +5 -13
- package/skills/design-planning/global-overlay-stack-standard/SKILL.md +73 -0
- package/skills/design-planning/ui-motion-interaction-standard/SKILL.md +69 -0
- package/skills/design-planning/ui-sdd-specialized/SKILL.md +5 -14
- package/skills/development-execution/flutter-errors/SKILL.md +5 -15
- package/skills/flutter-skills/.github/dependabot.yaml +15 -0
- package/skills/flutter-skills/.github/workflows/dart_skills_lint_workflow.yaml +68 -0
- package/skills/flutter-skills/.github/workflows/skills_tool.yaml +51 -0
- package/skills/flutter-skills/CODE_OF_CONDUCT.md +3 -0
- package/skills/flutter-skills/CONTRIBUTING.md +36 -0
- package/skills/flutter-skills/LICENSE +26 -0
- package/skills/flutter-skills/README.md +50 -0
- package/skills/flutter-skills/pubspec.yaml +9 -0
- package/skills/flutter-skills/resources/flutter_skills.yaml +434 -0
- package/skills/flutter-skills/skills/flutter-add-integration-test/SKILL.md +163 -0
- package/skills/flutter-skills/skills/flutter-add-widget-preview/SKILL.md +145 -0
- package/skills/flutter-skills/skills/flutter-add-widget-test/SKILL.md +154 -0
- package/skills/flutter-skills/skills/flutter-apply-architecture-best-practices/SKILL.md +162 -0
- package/skills/flutter-skills/skills/flutter-build-responsive-layout/SKILL.md +139 -0
- package/skills/flutter-skills/skills/flutter-fix-layout-issues/SKILL.md +130 -0
- package/skills/flutter-skills/skills/flutter-implement-json-serialization/SKILL.md +153 -0
- package/skills/flutter-skills/skills/flutter-setup-declarative-routing/SKILL.md +255 -0
- package/skills/flutter-skills/skills/flutter-setup-localization/SKILL.md +210 -0
- package/skills/flutter-skills/skills/flutter-use-http-package/SKILL.md +175 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/add-dart-lint-validation-rule/SKILL.md +196 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-best-practices/SKILL.md +65 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-checks-migration/SKILL.md +158 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-cli-app-best-practices/SKILL.md +168 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-doc-validation/SKILL.md +87 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-long-lines/SKILL.md +101 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-matcher-best-practices/SKILL.md +136 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-modern-features/SKILL.md +266 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-package-maintenance/SKILL.md +92 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/SKILL.md +92 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/example/lib/src/calculator.dart +7 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/example/pubspec.yaml +8 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/example/test/calculator_test.dart +11 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/scripts/interpret_coverage.dart +95 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/scripts/pubspec.yaml +6 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-coverage/scripts/test/interpret_coverage_test.dart +93 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/dart-test-fundamentals/SKILL.md +173 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/definition-of-done/SKILL.md +27 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/flutter_skills_ignore.json +3 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/grill-me/SKILL.md +10 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/ignore.json +3 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/test-driven-development/SKILL.md +371 -0
- package/skills/flutter-skills/tool/dart_skills_lint/.agents/skills/test-driven-development/testing-anti-patterns.md +299 -0
- package/skills/flutter-skills/tool/dart_skills_lint/AUTHORS +7 -0
- package/skills/flutter-skills/tool/dart_skills_lint/CHANGELOG.md +12 -0
- package/skills/flutter-skills/tool/dart_skills_lint/CONTRIBUTING.md +51 -0
- package/skills/flutter-skills/tool/dart_skills_lint/LICENSE +27 -0
- package/skills/flutter-skills/tool/dart_skills_lint/README.md +203 -0
- package/skills/flutter-skills/tool/dart_skills_lint/analysis_options.yaml +296 -0
- package/skills/flutter-skills/tool/dart_skills_lint/bench/README.md +23 -0
- package/skills/flutter-skills/tool/dart_skills_lint/bench/baseline_throughput.dart +230 -0
- package/skills/flutter-skills/tool/dart_skills_lint/bin/cli.dart +10 -0
- package/skills/flutter-skills/tool/dart_skills_lint/dart_skills_lint.yaml +14 -0
- package/skills/flutter-skills/tool/dart_skills_lint/documentation/feature_design_docs/PRODUCTION_READYNESS.md +48 -0
- package/skills/flutter-skills/tool/dart_skills_lint/documentation/feature_design_docs/completion_migration_plan.md +99 -0
- package/skills/flutter-skills/tool/dart_skills_lint/documentation/feature_design_docs/legacy_patterns_report.md +110 -0
- package/skills/flutter-skills/tool/dart_skills_lint/documentation/feature_design_docs/pub_vs_skill_report.md +56 -0
- package/skills/flutter-skills/tool/dart_skills_lint/documentation/knowledge/SPECIFICATION.md +79 -0
- package/skills/flutter-skills/tool/dart_skills_lint/documentation/knowledge/architecture_overview.md +64 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/dart_skills_lint.dart +11 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/config_parser.dart +156 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/entry_point.dart +354 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/fixable_rule.dart +20 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/analysis_severity.dart +15 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/check_type.dart +17 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/ignore_entry.dart +34 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/ignore_entry.g.dart +19 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/skill_context.dart +27 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/skill_rule.dart +27 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/skills_ignores.dart +26 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/skills_ignores.g.dart +24 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/models/validation_error.dart +31 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rule_registry.dart +79 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/absolute_paths_rule.dart +74 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/description_length_rule.dart +49 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/disallowed_field_rule.dart +61 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/name_format_rule.dart +167 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/relative_paths_rule.dart +72 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/trailing_whitespace_rule.dart +93 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/rules/valid_yaml_metadata_rule.dart +74 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/skills_ignores_storage.dart +36 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/validation_session.dart +559 -0
- package/skills/flutter-skills/tool/dart_skills_lint/lib/src/validator.dart +238 -0
- package/skills/flutter-skills/tool/dart_skills_lint/pubspec.yaml +28 -0
- package/skills/flutter-skills/tool/dart_skills_lint/skills/README.md +10 -0
- package/skills/flutter-skills/tool/dart_skills_lint/skills/dart-skills-lint-validation/SKILL.md +195 -0
- package/skills/flutter-skills/tool/dart_skills_lint/skills-lock.json +75 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/absolute_paths_test.dart +167 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/cli_integration_test.dart +683 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/config_file_test.dart +292 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/custom_rule_test.dart +122 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/directory_structure_test.dart +163 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/field_constraints_test.dart +178 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/fixer_test.dart +172 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/ignore_models_test.dart +63 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/metadata_validation_test.dart +116 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/relative_path_flag_test.dart +70 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/relative_paths_test.dart +172 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/resolve_rules_test.dart +82 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/rule_naming_test.dart +29 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/skills_ignores_storage_test.dart +89 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/test_utils.dart +19 -0
- package/skills/flutter-skills/tool/dart_skills_lint/test/trailing_whitespace_test.dart +152 -0
- package/skills/flutter-skills/tool/generator/README.md +150 -0
- package/skills/flutter-skills/tool/generator/analysis_options.yaml +143 -0
- package/skills/flutter-skills/tool/generator/bin/skills.dart +73 -0
- package/skills/flutter-skills/tool/generator/lib/src/commands/base_skill_command.dart +87 -0
- package/skills/flutter-skills/tool/generator/lib/src/commands/base_yaml_command.dart +83 -0
- package/skills/flutter-skills/tool/generator/lib/src/commands/generate_skill_command.dart +92 -0
- package/skills/flutter-skills/tool/generator/lib/src/commands/update_readme_command.dart +150 -0
- package/skills/flutter-skills/tool/generator/lib/src/commands/update_skill_command.dart +97 -0
- package/skills/flutter-skills/tool/generator/lib/src/commands/validate_skill_command.dart +284 -0
- package/skills/flutter-skills/tool/generator/lib/src/models/skill_params.dart +41 -0
- package/skills/flutter-skills/tool/generator/lib/src/services/gemini_service.dart +310 -0
- package/skills/flutter-skills/tool/generator/lib/src/services/markdown_converter.dart +226 -0
- package/skills/flutter-skills/tool/generator/lib/src/services/prompts.dart +72 -0
- package/skills/flutter-skills/tool/generator/lib/src/services/resource_fetcher_service.dart +84 -0
- package/skills/flutter-skills/tool/generator/lib/src/services/skill_instructions.dart +30 -0
- package/skills/flutter-skills/tool/generator/pubspec.yaml +32 -0
- package/skills/flutter-skills/tool/generator/test/commands/base_skill_command_test.dart +131 -0
- package/skills/flutter-skills/tool/generator/test/commands/validate_skills_input_test.dart +263 -0
- package/skills/flutter-skills/tool/generator/test/custom_skill_rules/last_modified_rule.dart +32 -0
- package/skills/flutter-skills/tool/generator/test/generate_skills_retry_test.dart +105 -0
- package/skills/flutter-skills/tool/generator/test/generate_skills_test.dart +519 -0
- package/skills/flutter-skills/tool/generator/test/lint_skills_test.dart +34 -0
- package/skills/flutter-skills/tool/generator/test/markdown_converter_test.dart +103 -0
- package/skills/flutter-skills/tool/generator/test/markdown_table_test.dart +131 -0
- package/skills/flutter-skills/tool/generator/test/models/skill_params_test.dart +37 -0
- package/skills/flutter-skills/tool/generator/test/services/gemini_service_test.dart +291 -0
- package/skills/flutter-skills/tool/generator/test/services/markdown_converter_test.dart +156 -0
- package/skills/flutter-skills/tool/generator/test/services/resource_fetcher_service_test.dart +188 -0
- package/skills/flutter-skills/tool/generator/test/update_skills_test.dart +241 -0
- package/skills/flutter-skills/tool/generator/test/validate_skills_test.dart +728 -0
- package/skills/quality-assurance/bdd-acceptance/SKILL.md +5 -14
- package/skills/quality-assurance/flutter-test/SKILL.md +5 -16
- package/skills/rules/project_rules.md +538 -127
- package/skills/special-tools/env-check/SKILL.md +5 -13
- package/skills/special-tools/ios-full-auto-debug/SKILL.md +5 -15
- package/skills/writing-skills/SKILL.md +654 -0
- package/skills/writing-skills/anthropic-best-practices.md +1149 -0
- package/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
- package/skills/writing-skills/graphviz-conventions.dot +172 -0
- package/skills/writing-skills/persuasion-principles.md +187 -0
- package/skills/writing-skills/render-graphs.js +168 -0
- package/skills/writing-skills/testing-skills-with-subagents.md +384 -0
- package/skills/checklist.md +0 -154
- package/skills/rules/user_rules.md +0 -263
- package/skills//345/256/214/346/225/264/345/274/200/345/217/221/346/265/201/347/250/213/346/211/213/345/206/214.md +0 -454
- package/skills//346/212/200/350/203/275/344/275/223/347/263/273/345/256/214/345/226/204/345/273/272/350/256/256.md +0 -308
- package/skills//346/212/200/350/203/275/344/275/277/347/224/250/346/214/207/345/215/227.md +0 -309
- package/skills//346/212/200/350/203/275/345/206/263/347/255/226/346/240/221.md +0 -338
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
【claude code调用标识:flutter-setup-localization】【trae调用标识:flutter-setup-localization+Flutter开发】【流程场景:1.完整3阶段SDD流程、3.小型功能迭代】
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
name: flutter-setup-localization
|
|
5
|
+
description: Add `flutter_localizations` and `intl` dependencies, enable "generate true" in `pubspec.yaml`, and create an `l10n.yaml` configuration file. Use when initializing localization support for a new Flutter project.
|
|
6
|
+
metadata:
|
|
7
|
+
model: models/gemini-3.1-pro-preview
|
|
8
|
+
last_modified: Tue, 21 Apr 2026 21:27:35 GMT
|
|
9
|
+
---
|
|
10
|
+
# Internationalizing Flutter Applications
|
|
11
|
+
|
|
12
|
+
## Contents
|
|
13
|
+
- [Core Concepts](#core-concepts)
|
|
14
|
+
- [Setup Workflow](#setup-workflow)
|
|
15
|
+
- [Implementation Workflow](#implementation-workflow)
|
|
16
|
+
- [Advanced Formatting](#advanced-formatting)
|
|
17
|
+
- [Examples](#examples)
|
|
18
|
+
|
|
19
|
+
## Core Concepts
|
|
20
|
+
Flutter handles internationalization (i18n) and localization (l10n) via the `flutter_localizations` and `intl` packages. The standard approach uses App Resource Bundle (`.arb`) files to define localized strings, which are then compiled into a generated `AppLocalizations` class for type-safe access within the widget tree.
|
|
21
|
+
|
|
22
|
+
## Setup Workflow
|
|
23
|
+
|
|
24
|
+
Copy and track this checklist when initializing internationalization in a Flutter project:
|
|
25
|
+
|
|
26
|
+
- [ ] **Task Progress**
|
|
27
|
+
- [ ] 1. Add dependencies to `pubspec.yaml`.
|
|
28
|
+
- [ ] 2. Enable the `generate` flag.
|
|
29
|
+
- [ ] 3. Create the `l10n.yaml` configuration file.
|
|
30
|
+
- [ ] 4. Configure `MaterialApp` or `CupertinoApp`.
|
|
31
|
+
|
|
32
|
+
### 1. Add Dependencies
|
|
33
|
+
Add the required localization packages to the project. Execute the following commands in the terminal:
|
|
34
|
+
```bash
|
|
35
|
+
flutter pub add flutter_localizations --sdk=flutter
|
|
36
|
+
flutter pub add intl:any
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Verify your `pubspec.yaml` includes the following under `dependencies`:
|
|
40
|
+
```yaml
|
|
41
|
+
dependencies:
|
|
42
|
+
flutter:
|
|
43
|
+
sdk: flutter
|
|
44
|
+
flutter_localizations:
|
|
45
|
+
sdk: flutter
|
|
46
|
+
intl: any
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 2. Enable Code Generation
|
|
50
|
+
Open `pubspec.yaml` and enable the `generate` flag within the `flutter` section to automate localization tasks:
|
|
51
|
+
```yaml
|
|
52
|
+
flutter:
|
|
53
|
+
generate: true
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 3. Create Configuration File
|
|
57
|
+
Create a new file named `l10n.yaml` in the root directory of the Flutter project. Define the input directory, template file, and output file:
|
|
58
|
+
```yaml
|
|
59
|
+
arb-dir: lib/l10n
|
|
60
|
+
template-arb-file: app_en.arb
|
|
61
|
+
output-localization-file: app_localizations.dart
|
|
62
|
+
synthetic-package: true
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 4. Configure the App Entry Point
|
|
66
|
+
Import the generated localizations and the `flutter_localizations` library in your `main.dart`. Inject the delegates and supported locales into your `MaterialApp` or `CupertinoApp`.
|
|
67
|
+
|
|
68
|
+
```dart
|
|
69
|
+
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
70
|
+
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; // Adjust path if synthetic-package is false
|
|
71
|
+
|
|
72
|
+
// ... inside build method
|
|
73
|
+
return MaterialApp(
|
|
74
|
+
localizationsDelegates: const [
|
|
75
|
+
AppLocalizations.delegate,
|
|
76
|
+
GlobalMaterialLocalizations.delegate,
|
|
77
|
+
GlobalWidgetsLocalizations.delegate,
|
|
78
|
+
GlobalCupertinoLocalizations.delegate,
|
|
79
|
+
],
|
|
80
|
+
supportedLocales: const [
|
|
81
|
+
Locale('en'), // English
|
|
82
|
+
Locale('es'), // Spanish
|
|
83
|
+
],
|
|
84
|
+
home: const MyHomePage(),
|
|
85
|
+
);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Implementation Workflow
|
|
89
|
+
|
|
90
|
+
Follow this workflow when adding or modifying localized content.
|
|
91
|
+
|
|
92
|
+
### 1. Define ARB Files
|
|
93
|
+
* **If creating NEW content:** Add the base string to the template file (`lib/l10n/app_en.arb`). Include a description for context.
|
|
94
|
+
* **If EDITING existing content:** Locate the key in all supported `.arb` files and update the values.
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"helloWorld": "Hello World!",
|
|
99
|
+
"@helloWorld": {
|
|
100
|
+
"description": "The conventional newborn programmer greeting"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Create corresponding files for other locales (e.g., `app_es.arb`):
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"helloWorld": "¡Hola Mundo!"
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 2. Generate Localization Classes
|
|
113
|
+
Run the following command to trigger code generation:
|
|
114
|
+
```bash
|
|
115
|
+
flutter pub get
|
|
116
|
+
```
|
|
117
|
+
*Feedback Loop:* Run validator -> review terminal output for ARB syntax errors -> fix missing commas or mismatched placeholders -> re-run `flutter pub get`.
|
|
118
|
+
|
|
119
|
+
### 3. Consume Localized Strings
|
|
120
|
+
Access the localized strings in your widget tree using `AppLocalizations.of(context)`. Ensure the widget calling this is a descendant of `MaterialApp`.
|
|
121
|
+
|
|
122
|
+
```dart
|
|
123
|
+
Text(AppLocalizations.of(context)!.helloWorld)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Advanced Formatting
|
|
127
|
+
|
|
128
|
+
Use placeholders for dynamic data, plurals, and conditional selects.
|
|
129
|
+
|
|
130
|
+
### Placeholders
|
|
131
|
+
Define parameters within curly braces and specify their type in the metadata object.
|
|
132
|
+
```json
|
|
133
|
+
"hello": "Hello {userName}",
|
|
134
|
+
"@hello": {
|
|
135
|
+
"description": "A message with a single parameter",
|
|
136
|
+
"placeholders": {
|
|
137
|
+
"userName": {
|
|
138
|
+
"type": "String",
|
|
139
|
+
"example": "Bob"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Plurals
|
|
146
|
+
Use the `plural` syntax to handle quantity-based string variations. The `other` case is mandatory.
|
|
147
|
+
```json
|
|
148
|
+
"nWombats": "{count, plural, =0{no wombats} =1{1 wombat} other{{count} wombats}}",
|
|
149
|
+
"@nWombats": {
|
|
150
|
+
"description": "A plural message",
|
|
151
|
+
"placeholders": {
|
|
152
|
+
"count": {
|
|
153
|
+
"type": "num",
|
|
154
|
+
"format": "compact"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Selects
|
|
161
|
+
Use the `select` syntax for conditional strings, such as gendered text.
|
|
162
|
+
```json
|
|
163
|
+
"pronoun": "{gender, select, male{he} female{she} other{they}}",
|
|
164
|
+
"@pronoun": {
|
|
165
|
+
"description": "A gendered message",
|
|
166
|
+
"placeholders": {
|
|
167
|
+
"gender": {
|
|
168
|
+
"type": "String"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Examples
|
|
175
|
+
|
|
176
|
+
### Complete `l10n.yaml`
|
|
177
|
+
```yaml
|
|
178
|
+
arb-dir: lib/l10n
|
|
179
|
+
template-arb-file: app_en.arb
|
|
180
|
+
output-localization-file: app_localizations.dart
|
|
181
|
+
synthetic-package: true
|
|
182
|
+
use-escaping: true
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Complete Widget Implementation
|
|
186
|
+
```dart
|
|
187
|
+
import 'package:flutter/material.dart';
|
|
188
|
+
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
189
|
+
|
|
190
|
+
class GreetingWidget extends StatelessWidget {
|
|
191
|
+
final String userName;
|
|
192
|
+
final int notificationCount;
|
|
193
|
+
|
|
194
|
+
const GreetingWidget({
|
|
195
|
+
super.key,
|
|
196
|
+
required this.userName,
|
|
197
|
+
required this.notificationCount,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
@override
|
|
201
|
+
Widget build(BuildContext context) {
|
|
202
|
+
final l10n = AppLocalizations.of(context)!;
|
|
203
|
+
|
|
204
|
+
return Column(
|
|
205
|
+
children: [
|
|
206
|
+
Text(l10n.hello(userName)),
|
|
207
|
+
Text(l10n.nWombats(notificationCount)),
|
|
208
|
+
],
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
```
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
【claude code调用标识:flutter-use-http-package】【trae调用标识:flutter-use-http-package+Flutter开发】【流程场景:1.完整3阶段SDD流程、3.小型功能迭代】
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
name: flutter-use-http-package
|
|
5
|
+
description: Use the `http` package to execute GET, POST, PUT, or DELETE requests. Use when you need to fetch from or send data to a REST API.
|
|
6
|
+
metadata:
|
|
7
|
+
model: models/gemini-3.1-pro-preview
|
|
8
|
+
last_modified: Tue, 21 Apr 2026 21:36:42 GMT
|
|
9
|
+
---
|
|
10
|
+
# Implementing Flutter Networking
|
|
11
|
+
|
|
12
|
+
## Contents
|
|
13
|
+
- [Configuration & Permissions](#configuration--permissions)
|
|
14
|
+
- [Request Execution & Response Handling](#request-execution--response-handling)
|
|
15
|
+
- [Background Parsing](#background-parsing)
|
|
16
|
+
- [Workflow: Executing Network Operations](#workflow-executing-network-operations)
|
|
17
|
+
- [Examples](#examples)
|
|
18
|
+
|
|
19
|
+
## Configuration & Permissions
|
|
20
|
+
|
|
21
|
+
Configure the environment and platform-specific permissions required for network access.
|
|
22
|
+
|
|
23
|
+
1. Add the `http` package dependency via the terminal:
|
|
24
|
+
```bash
|
|
25
|
+
flutter pub add http
|
|
26
|
+
```
|
|
27
|
+
2. Import the package in your Dart files:
|
|
28
|
+
```dart
|
|
29
|
+
import 'package:http/http.dart' as http;
|
|
30
|
+
```
|
|
31
|
+
3. Configure Android permissions by adding the Internet permission to `android/app/src/main/AndroidManifest.xml`:
|
|
32
|
+
```xml
|
|
33
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
34
|
+
```
|
|
35
|
+
4. Configure macOS entitlements by adding the network client key to both `macos/Runner/DebugProfile.entitlements` and `macos/Runner/Release.entitlements`:
|
|
36
|
+
```xml
|
|
37
|
+
<key>com.apple.security.network.client</key>
|
|
38
|
+
<true/>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Request Execution & Response Handling
|
|
42
|
+
|
|
43
|
+
Execute HTTP operations and map responses to strongly typed Dart objects.
|
|
44
|
+
|
|
45
|
+
* **URIs:** Always parse URL strings using `Uri.parse('your_url')`.
|
|
46
|
+
* **Headers:** Inject authorization and content-type headers via the `headers` parameter map. Use `HttpHeaders.authorizationHeader` for auth tokens.
|
|
47
|
+
* **Payloads:** For POST and PUT requests, encode the body using `jsonEncode()` from `dart:convert`.
|
|
48
|
+
* **Status Validation:** Evaluate `response.statusCode`. Treat `200 OK` (GET/PUT/DELETE) and `201 CREATED` (POST) as success.
|
|
49
|
+
* **Error Handling:** Throw explicit exceptions for non-success status codes. Never return `null` on failure, as this prevents `FutureBuilder` from triggering its error state and causes infinite loading indicators.
|
|
50
|
+
* **Deserialization:** Parse the raw string using `jsonDecode(response.body)` and map it to a custom Dart object using a factory constructor (e.g., `fromJson`).
|
|
51
|
+
|
|
52
|
+
## Background Parsing
|
|
53
|
+
|
|
54
|
+
Offload expensive JSON parsing to a separate Isolate to prevent UI jank (frame drops).
|
|
55
|
+
|
|
56
|
+
* Import `package:flutter/foundation.dart`.
|
|
57
|
+
* Use the `compute()` function to run the parsing logic in a background isolate.
|
|
58
|
+
* Ensure the parsing function passed to `compute()` is a top-level function or a static method, as closures or instance methods cannot be passed across isolates.
|
|
59
|
+
|
|
60
|
+
## Workflow: Executing Network Operations
|
|
61
|
+
|
|
62
|
+
Use the following checklist to implement and validate network operations.
|
|
63
|
+
|
|
64
|
+
**Task Progress:**
|
|
65
|
+
- [ ] 1. Define the strongly typed Dart model with a `fromJson` factory constructor.
|
|
66
|
+
- [ ] 2. Implement the network request method returning a `Future<Model>`.
|
|
67
|
+
- [ ] 3. Apply conditional logic based on the operation type:
|
|
68
|
+
- **If fetching data (GET):** Append query parameters to the URI.
|
|
69
|
+
- **If mutating data (POST/PUT):** Set `'Content-Type': 'application/json; charset=UTF-8'` and attach the `jsonEncode` body.
|
|
70
|
+
- **If deleting data (DELETE):** Return an empty model instance on success (`200 OK`).
|
|
71
|
+
- [ ] 4. Validate the `statusCode` and throw an `Exception` on failure.
|
|
72
|
+
- [ ] 5. Integrate the `Future` into the UI using `FutureBuilder`.
|
|
73
|
+
- [ ] 6. Handle `snapshot.hasData`, `snapshot.hasError`, and default to a `CircularProgressIndicator`.
|
|
74
|
+
- [ ] 7. **Feedback Loop:** Run the app -> trigger the network request -> review console for unhandled exceptions -> fix parsing or permission errors.
|
|
75
|
+
|
|
76
|
+
## Examples
|
|
77
|
+
|
|
78
|
+
### High-Fidelity Implementation: Fetching and Parsing in the Background
|
|
79
|
+
|
|
80
|
+
```dart
|
|
81
|
+
import 'dart:async';
|
|
82
|
+
import 'dart:convert';
|
|
83
|
+
import 'dart:io';
|
|
84
|
+
import 'package:flutter/foundation.dart';
|
|
85
|
+
import 'package:flutter/material.dart';
|
|
86
|
+
import 'package:http/http.dart' as http;
|
|
87
|
+
|
|
88
|
+
// 1. Top-level parsing function for Isolate
|
|
89
|
+
List<Photo> parsePhotos(String responseBody) {
|
|
90
|
+
final parsed = (jsonDecode(responseBody) as List<Object?>)
|
|
91
|
+
.cast<Map<String, Object?>>();
|
|
92
|
+
return parsed.map<Photo>(Photo.fromJson).toList();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 2. Network execution with background parsing
|
|
96
|
+
Future<List<Photo>> fetchPhotos() async {
|
|
97
|
+
final response = await http.get(
|
|
98
|
+
Uri.parse('https://jsonplaceholder.typicode.com/photos'),
|
|
99
|
+
headers: {
|
|
100
|
+
HttpHeaders.authorizationHeader: 'Bearer your_token_here',
|
|
101
|
+
HttpHeaders.acceptHeader: 'application/json',
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
if (response.statusCode == 200) {
|
|
106
|
+
// Offload heavy parsing to a background isolate
|
|
107
|
+
return compute(parsePhotos, response.body);
|
|
108
|
+
} else {
|
|
109
|
+
throw Exception('Failed to load photos. Status: ${response.statusCode}');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 3. Strongly typed model
|
|
115
|
+
class Photo {
|
|
116
|
+
final int id;
|
|
117
|
+
final String title;
|
|
118
|
+
final String thumbnailUrl;
|
|
119
|
+
|
|
120
|
+
const Photo({
|
|
121
|
+
required this.id,
|
|
122
|
+
required this.title,
|
|
123
|
+
required this.thumbnailUrl,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
factory Photo.fromJson(Map<String, dynamic> json) {
|
|
127
|
+
return Photo(
|
|
128
|
+
id: json['id'] as int,
|
|
129
|
+
title: json['title'] as String,
|
|
130
|
+
thumbnailUrl: json['thumbnailUrl'] as String,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// 4. UI Integration
|
|
136
|
+
class PhotoGallery extends StatefulWidget {
|
|
137
|
+
const PhotoGallery({super.key});
|
|
138
|
+
|
|
139
|
+
@override
|
|
140
|
+
State<PhotoGallery> createState() => _PhotoGalleryState();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
class _PhotoGalleryState extends State<PhotoGallery> {
|
|
144
|
+
late Future<List<Photo>> _futurePhotos;
|
|
145
|
+
|
|
146
|
+
@override
|
|
147
|
+
void initState() {
|
|
148
|
+
super.initState();
|
|
149
|
+
// Initialize Future once to prevent re-fetching on rebuilds
|
|
150
|
+
_futurePhotos = fetchPhotos();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@override
|
|
154
|
+
Widget build(BuildContext context) {
|
|
155
|
+
return FutureBuilder<List<Photo>>(
|
|
156
|
+
future: _futurePhotos,
|
|
157
|
+
builder: (context, snapshot) {
|
|
158
|
+
if (snapshot.hasData) {
|
|
159
|
+
final photos = snapshot.data!;
|
|
160
|
+
return ListView.builder(
|
|
161
|
+
itemCount: photos.length,
|
|
162
|
+
itemBuilder: (context, index) => ListTile(
|
|
163
|
+
leading: Image.network(photos[index].thumbnailUrl),
|
|
164
|
+
title: Text(photos[index].title),
|
|
165
|
+
),
|
|
166
|
+
);
|
|
167
|
+
} else if (snapshot.hasError) {
|
|
168
|
+
return Center(child: Text('Error: ${snapshot.error}'));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Default loading state
|
|
172
|
+
return const Center(child: CircularProgressIndicator());
|
|
173
|
+
},
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
```
|