home_widget generate
Generate native widget code and a Dart helper from a schema file.
generate
Generate native iOS and Android widget code, plus a typed Dart helper, from @HomeWidget annotated schema files defined with home_widget_generator.
dart run home_widget_cli generate [options]
Behavior
- The default input is the
home_widget/directory at the project root. Pass a different file or directory with--input. - If the input is a directory, every
.dartfile in it is scanned recursively for@HomeWidgetannotations. - For each widget found:
- A Dart helper is written to
lib/src/home_widget/<schema-file>.home_widget.dartby default, where<schema-file>is the schema's file name without extension. - iOS code is written under
ios/if the schema declares aniOSconfig. - Android code is written under
android/if the schema declares anandroidconfig.
- A Dart helper is written to
- The Dart helper output location can be overridden:
--dart-outon the CLI takes priority.- Otherwise the schema's
dartOutputis used. - Otherwise the default
lib/src/home_widget/...is used.
--dart-outresolution rules:- A path ending in
.dartis treated as the exact output file. - A path with no extension (or an existing directory) is treated as a directory; the auto-generated file name
<schema-file>.home_widget.dartis appended. - Any other extension is rejected.
- A path ending in
- The
home_widgetpackage is automatically added to yourpubspec.yamlif it isn't already listed as a dependency.
Options
| Option | Description | Default |
|---|---|---|
-i, --input=<path> | Path to schema file or directory. | home_widget/ |
--dart-out=<path> | Output path for the generated Dart helper. Can be a .dart file path or a directory. | lib/src/home_widget/<schema>.home_widget.dart |
Examples
Generate from the default home_widget/ directory:
dart run home_widget_cli generate
Generate from a specific schema file:
dart run home_widget_cli generate --input home_widget/my_widget.dart
Write the Dart helper into a custom directory:
dart run home_widget_cli generate --dart-out lib/widgets/