flutter/website/data-model
Claude Code and agent skill by flutter/website
- community
Checking that the SKILL.md file is still in the repository.
Add or update a dart_mappable data model in lib/src/models/content/, including adding format validation, regenerating code, and adding tests. Use when adding a new content type or modifying an existing model's fields.
Install
npx vskill@latest install flutter/website/data-modelSKILL.md
The same SKILL.md was published earlier as flutter/website/data-model.
Data model skill
Add or update a typed content model in this project. Follow the established conventions below as much as possible.
Before starting
- If updating an existing model, read the model file,
its source YAML or JSON file(s), and its test group first.
- If adding a new model, identify which page will use it and
the structure of the YAML file it will load from and map to. If the YAML file doesn't exist, ask the user to create and reference it or provide information about its expected structure.
Model file conventions
All data models live in the lib/src/models/content directory and should roughly follow this general structure:
When adding a new data model, consider checking the format of one or more existing models in the lib/src/models/content/ directory.
Key guidelines
- The Dart code you write for the models should follow
Effective Dart and other Dart best practices and standards.
- Import the
content_validation.dartlibrary and
use its helper functions to validate the contents of each field.
- The
partdirective must point to<filename>.mapper.dart.
That part file is generated when running build_runner.
- The mixed-in mixin's name is always
<ClassName>Mappable.
That mixin is generated when running build_runner.
- The
fromJsonfactory delegates to<ClassName>Mapper.fromMap(json). - Use
@MappableField(key: 'yaml_key')when the YAML key uses
snake_case or otherwise differs from the camelCase Dart field name.
- When a field is limited to a set of allowed values,
create and use a new enum for the Dart type. To be serialized and deserialized, annotate the enum with @MappableEnum.
- For fields that need custom deserialization from YAML strings,
create a private MappingHook subclass in the same file.
- All fields on the class should be statically typed and marked
final. - Add documentation comments on the class and on every field,
following Effective Dart guidelines for doc comments.
- The class doc comment must include an "Expected data format" section
listing each field, its brief meaning, and its constraints.
Validation rules
When users might make a mistake or a specific format is needed, fields should be validated in the constructor body, not just by Dart's type system.
Validation helpers are defined in the lib/src/models/content/content_validation.dart library. Some common validations include:
| Field type | Validation | |
|---|---|---|
| Required string | checkFormat(isNotBlank(field), '...') | |
| Optional string | if (field case final field?) checkFormat(isNotBlank(field), '...') | |
| Absolute URL | checkFormat(isAbsoluteHttpUrl(field), '...') | |
| Image asset path | checkFormat(looksLikeImageAssetPath(field), '...') | |
| Hex color | checkFormat(isHexColor(field), '...') | |
| Non-empty list | checkFormat(field.isNotEmpty, '...') |
As appropriate, multiple validations can be completed. Complete the less specific ones first, such as not being blank.
If you think any other validation is needed or might be helpful:
- Ensure it doesn't already exist in the
content_validation.dartlibrary. - Add a reusable function to the
content_validation.dartlibrary. - Provide a useful doc comment, following Effective Dart best practices.
- If it might be commonly useful, add it to this skill's table.
- Make use of the new validation in the constructor body.
After creating or modifying the model file
- Run code generation to produce or update the
.mapper.dartfile:
``bash dart run build_runner build --delete-conflicting-outputs ``
- Add or update tests in
test/models/content/content_models_test.dart.
Read the file to understand the existing testing patterns, import the new model, and add a test group following a similar pattern.
The test file already defines a few custom matchers. If needed, reuse them, don't unnecessarily redefine them.
_throwsMapperException:
For fields that are missing or have the wrong type.
_throwsValidationError:
For fields that exist but fail validation.
- Run tests to verify:
``bash dart test test/models/content/content_models_test.dart ``
- Run analysis to catch any lint issues:
``bash dart analyze lib/src/models/content/ ``
Use the data model from a page
If you already are or want to use the data in a page, access the data using the decodeJsonList and decodeJsonObject extension methods on BuildContext. At the beginning of a page component's build method, use the extension methods and store the data in a variable for reuse.
The dot-notation path maps to the content directory structure. For example, page_name.data_key resolves to content/page_name/data_key.yaml.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingsites/www/.agents/skills/data-model/SKILL.md
Popularity
- Repository stars
- 3,082
- Repository forks
- 3,465
- 7-day trend score
- 40
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/flutter/website/data-model)