flutter/dev/tools/gen_defaults
2023-02-10 23:11:53 +00:00
..
bin Revert "Update ExpansionTile to support Material 3 & add an example (#119712)" (#120300) 2023-02-08 10:53:55 -08:00
data Update to v0.158 of the token database. (#120149) 2023-02-07 19:16:24 +00:00
lib Add proper disabled values for input chips (#120192) 2023-02-09 16:51:26 +00:00
test Refactor gen_defaults to support multiple generated code blocks in the same file independently. (#107278) 2022-07-10 17:17:09 -07:00
pubspec.yaml roll packages (#120493) 2023-02-10 23:11:53 +00:00
README.md Refactor gen_defaults to support multiple generated code blocks in the same file independently. (#107278) 2022-07-10 17:17:09 -07:00

Token Defaults Generator

Script that generates widget component theme data defaults based on the Material Token database. These tokens were extracted into a JSON file from an internal Google database.

Usage

Run this program from the root of the git repository:

dart dev/tools/gen_defaults/bin/gen_defaults.dart

Templates

There is a template file for every component that needs defaults from the token database. These templates are implemented as subclasses of TokenTemplate. This base class provides some utilities and a structure for adding a new block of generated code to the bottom of a given file.

Templates need to override the generate method to provide the generated code block as a string. The tokens are represented as a Map<String, dynamic> that is loaded from data/material-tokens.json. Templates can look up whatever properties are needed in this structure to provide the properties needed for the component.

See lib/fab_template.dart for an example that generates defaults for the Floating Action Button.