FlutterInit uses Handlebars.js to dynamically generate Dart code. This guide covers the custom helpers and logical patterns used throughout our .hbs templates.
Use standard Handlebars {{#if}} and {{#unless}} blocks to toggle code sections based on configuration flags.
Standard Handlebars does not support complex logic inside {{#if}}. We provide several helpers to handle multi-flag conditions.
| Helper | Syntax | Description |
|---|---|---|
eq |
{{#if (eq a b)}} |
Checks for strict equality (===). useful for architecture or stateManagement strings. |
and |
{{#if (and a b c)}} |
Returns true if ALL arguments are truthy. |
or |
{{#if (or a b)}} |
Returns true if ANY argument is truthy. |
not |
{{#if (not a)}} |
Inverts the boolean value. |
when |
{{#when condition}}...{{/when}} |
A block helper for inline logic. |
Use these to ensure your class names and filenames match your project's naming conventions.
{{pascalCase appName}}:my cool app->MyCoolApp(Use for Classes){{snakeCase appName}}:my cool app->my_cool_app(Use for Filenames/Packages){{kebabCase appName}}:my cool app->my-cool-app(Use for URLs/IDs)
Important: Never hardcode pixel values like 16.0 if you want to support ScreenUtil. Use the res helper to automatically map to .w, .h, or .sp based on the user's preference.
- Syntax:
{{res VALUE UNIT_TYPE usesScreenutilFlag}} - Units:
'w'(width),'h'(height),'sp'(font/icon size)
Serializes an object or array into a pretty-printed JSON string. Useful for SETUP.md or configuration files.
Ensures that partials or multi-line strings maintain the correct indentation level when injected into a parent file.
Reusable code blocks are stored in templates/flutter/partials/. You can include them using the standard Handlebars syntax:
Next Step: See CONTRIBUTING.md to learn how to add your own patterns using these helpers.