flutter/dev/tools/gen_defaults
Michael Goderbauer 25e38a2a87
Bump lower Dart SDK constraints to 3.0 & add class modifiers (#122546)
Bump lower Dart SDK constraints to 3.0 & add class modifiers
2023-03-21 20:21:58 +00:00
..
bin Create SearchBar and SearchBarTheme (#122309) 2023-03-16 15:04:19 -07:00
data Run dart command to update widget defaults (#122557) 2023-03-15 18:53:29 +01:00
lib Update Material 3 bottom sheet (#122445) 2023-03-18 20:13:08 -07: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 Bump lower Dart SDK constraints to 3.0 & add class modifiers (#122546) 2023-03-21 20:21:58 +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.