AST-based Flutter UI Code Generator with Multi-Style Design System
Stop writing repetitive UI code. Define components once, render in any design system.
// Create meta/login.screen.dart
final loginScreen = ScreenDefinition(
id: 'login',
appBar: AstNode.appBar(title: 'Login'),
layout: AstNode.column(children: [
AstNode.text(text: 'Welcome', variant: TextVariant.headlineLarge),
AstNode.textField(label: 'Email', keyboardType: KeyboardType.email),
AstNode.textField(label: 'Password', obscureText: true),
AstNode.button(label: 'Login', onPressed: 'handleLogin'),
]),
);Run: dart run syntaxify build
Get: Complete Flutter screen in lib/screens/login_screen.dart
No boilerplate. No repetition. Just results. โจ
Check out the example app - A working Flutter app demonstrating all features with live style switching!
cd example && flutter runFlutter developers face a fundamental dilemma when building production apps:
The Multi-Platform UI Duplication Problem:
- Material Design for Android
- Cupertino for iOS
- Custom designs for brand identity
Traditional approach means writing everything 3 times:
// You write this for EVERY component!
Widget buildButton() {
if (Platform.isIOS) {
return CupertinoButton(
onPressed: onPressed,
child: Text(label),
);
} else if (useCustom) {
return CustomButton(
onPressed: onPressed,
label: label,
);
} else {
return ElevatedButton(
onPressed: onPressed,
child: Text(label),
);
}
}Real-World Impact:
- ๐ข Large Apps: 100+ screens, 1000+ components
- ๐ฅ Team Scale: Multiple developers, changing requirements
- ๐ Maintenance Nightmare: "Change all buttons to rounded corners" = touching 500+ files
- ๐ธ Cost: "Switch from Material to Cupertino" = rewriting the entire app
- ๐จ Design Changes: "Our designer wants a custom look" = building everything from scratch
Syntaxify delivers on Flutter's original promise: "write once, run anywhere" - but for design systems.
With Syntaxify:
// Write once
AppButton(label: 'Click Me', onPressed: ...)
// Renders appropriately everywhere
AppTheme(style: MaterialStyle()) // Material on Android
AppTheme(style: CupertinoStyle()) // iOS-native on iPhone
AppTheme(style: NeoStyle()) // Custom brand designChange your entire app's design system in one line:
// Before: Material Design
AppTheme(style: MaterialStyle(), child: MyApp())
// After: iOS-native Cupertino
AppTheme(style: CupertinoStyle(), child: MyApp())
// Zero component code changes needed!Most Flutter solutions offer partial fixes:
- โ Widget libraries - Still manual integration, not design-system-aware
- โ Themes - Only styling, not structure
- โ Code generation - Not multi-platform aware
Syntaxify combines all three:
- โ Code generation - Eliminate boilerplate
- โ Design system architecture - WHAT vs HOW separation
- โ Multi-platform rendering - One component, any design
- โ Type-safe APIs - Compile-time safety
Syntaxify uses a unique renderer pattern that separates concerns:
WHAT (Component Definition):
AppButton.primary(
label: 'Click Me',
onPressed: () => print('Hello!'),
)HOW (Style Rendering):
- Material: Renders as
ElevatedButtonwith Material Design tokens - Cupertino: Renders as
CupertinoButtonwith iOS styling - Neo: Renders with modern, neumorphic design
The Magic: Same component code, different visual output based on AppTheme:
AppTheme(
style: MaterialStyle(), // or CupertinoStyle() or NeoStyle()
child: MaterialApp(home: YourApp()),
)- Write Once, Render Anywhere - One component definition works across all design systems
- Easy Theme Switching - Change one line to switch your entire app's design
- Consistent Behavior - Button logic stays the same, only visuals change
- Custom Styles - Create your own design system by implementing
DesignStyle
The fastest way to build Flutter screens:
// meta/login.screen.dart
final loginScreen = ScreenDefinition(
id: 'login',
layout: AstNode.column(children: [
AstNode.text(text: 'Welcome Back'),
AstNode.textField(label: 'Email'),
AstNode.button(label: 'Sign In', onPressed: 'handleLogin'),
]),
);Run syntaxify build โ Get a complete Flutter screen!
- โ Generate entire screens from simple definitions
- โ Editable after generation (you own the code)
- โ Type-safe callbacks and imports
- โ Proper structure and scaffolding
- โ No boilerplate, no repetition
These components work with Material, Cupertino, and Neo styles:
- AppButton - Buttons with variants (primary, secondary, outlined)
- AppText - Text with typography variants (display, headline, title, body, label)
- AppInput - Text fields with validation and keyboard types
You can define custom components (e.g., Card, Badge, Avatar), and Syntaxify will:
- โ Generate the component class
- โ Create constructor and fields
โ ๏ธ Generate basic Container widget (not full renderer pattern yet)
Coming Soon: Full renderer pattern for more components (Card, Badge, Avatar, Chip, etc.)
Option A: From pub.dev (Recommended)
# pubspec.yaml
dev_dependencies:
syntaxify: ^0.1.0-alpha.1Then run:
dart pub getOption B: From GitHub (Latest)
# pubspec.yaml
dev_dependencies:
syntaxify:
git:
url: https://github.com/ihardk/syntaxify.git
ref: v0.1.0
path: generator
โ ๏ธ Alpha Release: This package is in alpha. API may change. See CHANGELOG for updates.
Optional: Global Installation
If you want syntaxify available system-wide (not just in your project):
dart pub global activate syntaxifyThen you can run syntaxify commands from anywhere. Otherwise, use dart run syntaxify in your project.
cd your_flutter_project
dart run syntaxify initThis creates:
meta/- Where you define component APIslib/syntaxify/design_system/- Customizable design system
Edit meta/button.meta.dart:
import 'package:syntaxify/syntaxify.dart';
@SyntaxComponent(description: 'A customizable button')
class ButtonMeta {
/// The button label text
@Required()
final String label;
/// The action to trigger (e.g. 'action:login')
@Optional()
final String? onPressed;
/// Button variant (filled, outlined, etc)
@Optional()
final String? variant;
/// Button size (sm, md, lg)
@Optional()
final String? size;
/// Whether the button shows loading state
@Optional()
@Default('false')
final bool isLoading;
/// Whether the button is disabled
@Optional()
@Default('false')
final bool isDisabled;
}dart run syntaxify buildThis generates:
lib/syntaxify/generated/components/app_button.dart- The componentlib/syntaxify/design_system/- Design system files (Material, Cupertino, Neo)lib/syntaxify/index.dart- Barrel export
import 'package:flutter/material.dart';
import 'package:your_app/syntaxify/index.dart';
void main() {
runApp(
AppTheme(
style: MaterialStyle(), // Try CupertinoStyle() or NeoStyle()!
child: MaterialApp(
home: Scaffold(
body: Center(
child: AppButton.primary(
label: 'Click Me',
onPressed: () => print('Hello from Syntaxify!'),
),
),
),
),
),
);
}Create meta/login.screen.dart:
import 'package:syntaxify/syntaxify.dart';
final loginScreen = ScreenDefinition(
id: 'login',
layout: AstNode.column(children: [
AstNode.text(text: 'Welcome Back'),
AstNode.textField(label: 'Email', keyboardType: KeyboardType.emailAddress),
AstNode.textField(label: 'Password', obscureText: true),
AstNode.button(label: 'Sign In', onPressed: 'handleLogin'),
]),
);Run dart run syntaxify build again - generates lib/screens/login_screen.dart (editable!)
Material Button:
ElevatedButton(
onPressed: onPressed,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
padding: EdgeInsets.all(16),
),
child: Text(label),
)Cupertino Button:
CupertinoButton.filled(
onPressed: onPressed,
padding: EdgeInsets.all(16),
child: Text(label),
)Custom Button:
Container(
decoration: BoxDecoration(
gradient: LinearGradient(...),
borderRadius: BorderRadius.circular(12),
boxShadow: [BoxShadow(...)],
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onPressed,
child: Padding(
padding: EdgeInsets.all(16),
child: Text(label),
),
),
),
)Problem: 3 different implementations, hard to maintain, inconsistent behavior.
One Definition:
AppButton.primary(label: 'Submit', onPressed: handleSubmit)Three Renderings:
- Wrap with
MaterialStyle()โ Material Design - Wrap with
CupertinoStyle()โ iOS Design - Wrap with
NeoStyle()โ Modern Design
Result: Consistent API, different visuals, easy to switch.
your_project/
โโโ meta/ # YOU EDIT: Component & screen definitions
โ โโโ button.meta.dart
โ โโโ input.meta.dart
โ โโโ text.meta.dart
โ โโโ login.screen.dart
โ โโโ app_icons.dart
โ
โโโ lib/
โโโ screens/ # EDITABLE: Generated screens
โ โโโ login_screen.dart # Generated once, then you own it
โ
โโโ syntaxify/
โโโ design_system/ # CUSTOMIZABLE: Styles & tokens
โ โโโ design_system.dart
โ โโโ app_theme.dart
โ โโโ styles/
โ โ โโโ material_style.dart
โ โ โโโ cupertino_style.dart
โ โ โโโ neo_style.dart
โ โโโ tokens/
โ โโโ button_tokens.dart
โ โโโ input_tokens.dart
โ
โโโ generated/ # DON'T EDIT: Auto-regenerated
โ โโโ components/
โ โโโ app_button.dart
โ โโโ app_input.dart
โ โโโ app_text.dart
โ
โโโ index.dart # Barrel export
For detailed API documentation, see API Reference.
Quick Overview:
| Component | Description |
|---|---|
AppButton |
Primary, secondary, outlined button variants |
AppText |
Typography with 6 text style variants |
AppInput |
Text fields with keyboard types & validation |
Design Styles: MaterialStyle(), CupertinoStyle(), NeoStyle()
Import: import 'package:your_app/syntaxify/index.dart';
- Define - Edit
meta/*.meta.dartto define component APIs - Build - Run
dart run syntaxify buildto generate implementations - Use - Import from
package:your_app/syntaxify/and use - Customize - Edit design system tokens in
lib/syntaxify/design_system/ - Switch Styles - Change
AppTheme(style: ...)to try different designs
Important: Two types of generated code with different lifecycles:
Location: lib/syntaxify/generated/components/
Behavior: Regenerated on EVERY syntaxify build
Rule:
// lib/syntaxify/generated/components/app_button.dart
// This file is REGENERATED on every build
class AppButton extends StatelessWidget {
// Generated code - DO NOT MODIFY
}Location: lib/screens/
Behavior: Generated ONCE, then YOU own it
Rule: โ
FREELY EDIT - Won't be overwritten
// lib/screens/login_screen.dart
// Generated once, then it's yours to edit
class LoginScreen extends StatelessWidget {
// Edit this freely - it won't be regenerated
}What happens when you rebuild?
- Components: Completely regenerated from meta files
- Screens: Skipped (only generated if file doesn't exist)
For advanced topics, see the detailed documentation:
- Design System Guide - Creating custom design styles, renderer pattern
- API Reference - Build options, CLI commands
Having issues? See Troubleshooting Guide for common errors and solutions.
Quick fixes:
TextVariant.headlineโ UseTextVariant.headlineMediumKeyboardType.emailโ UseTextInputType.emailAddress- Component not updating? โ Edit
meta/*.meta.dart, not generated files
Need help? GitHub Issues
- AST-Based Generation - Type-safe, declarative UI definitions
- Renderer Pattern - Separates WHAT (behavior) from HOW (rendering)
- Multi-Style Support - Material, Cupertino, Neo (3 components currently, more coming)
- Smart Defaults - Auto-detects project structure
- Screen Generation - Generate editable screen scaffolds
- Design Tokens - Centralized styling with tokens
- Git-Friendly - Clean, readable generated code
- Extensible - Create custom design styles by implementing
DesignStyle
v0.1.0 (Current)
- โ Core architecture with renderer pattern
- โ 3 components (Button, Text, Input)
- โ 3 design styles (Material, Cupertino, Neo)
- โ Screen generation
- โ Smart build defaults
v0.2.0 (Next)
- ๐ More components with full renderer pattern:
- Card, Badge, Avatar, Chip, Switch, Checkbox, Radio
- ๐ Golden tests for visual regression
- ๐ Better error messages
v1.0.0 (Future)
- ๐ฎ Complete component library
- ๐ฎ Theme editor UI
- ๐ฎ VS Code extension
- ๐ฎ Component marketplace
| Guide | Description |
|---|---|
| Getting Started | Installation & first steps |
| API Reference | Component usage & options |
| Design System | Renderer pattern & custom styles |
| Troubleshooting | Common issues & solutions |
| User Manual | Comprehensive user guide |
| Developer Manual | Architecture & contributing |
See Developer Manual for architecture details and contribution guidelines.
MIT License - See LICENSE for details
Built with โค๏ธ for Flutter developers who value consistency, productivity, and beautiful code
โญ Star us on GitHub โข ๐ฆ pub.dev โข โ Buy Me a Coffee
