About the YAML to Dart Converter
Flutter projects keep a surprising amount of YAML around: pubspec entries, CI definitions, feature flag files and localisation manifests. Reading one at runtime hands you a nested map, and the code that pulls values out of that map by string key is exactly the code that breaks silently when somebody renames a field. Generating typed classes from the YAML removes the string keys from your call sites.
The generator infers types from the values it finds. A scalar like 45.5 becomes a double, 3 becomes an int, quoted cron expressions stay String, and a list of mappings becomes a List of a class named after the singular of the key. Every class gets final fields, a const constructor with required named parameters, and fromMap plus toMap methods that recurse into nested types correctly.
One YAML specific point is worth knowing: a plain date like 2026-01-19 is parsed by the YAML spec as a date rather than a string, so quote it in the source if you want a String field in the generated class. Unquoted, it is typed as DateTime and read with DateTime.parse. Multiple documents separated by three dashes are not supported here, so split them first. For a straight data conversion without classes, YAML to JSON is the shorter path.
How to use
- Paste the YAML file you want a model for.
- Name the root class, since YAML has no root element to take the name from.
- Turn on Make every field nullable when the config often omits keys.
- Copy the classes into your Flutter project or download the
.dartfile.
Common questions
- Why is my date field a DateTime?
- YAML parses an unquoted ISO date as a date value. Wrap it in quotes in the source if you want it treated as a plain string.
- Can it read a multi document YAML file?
- No. Split documents separated by three dashes into separate runs, since each one describes a different shape.
- What happens with an empty list in the YAML?
- It becomes a dynamic list, because an empty list gives no information about what it will contain.
- Do anchors and aliases work?
- Yes. They are resolved while parsing, so the expanded values are what the generated model describes.