Why Migrate to Dart?
| Feature | JSON | Dart |
|---|---|---|
| Type Safety | No | Yes |
| IDE Autocompletion | Limited | Full |
| Compile-time Checks | No | Yes |
| Refactoring Support | Manual | Automatic |
| Code Organization | Files | Functions & Classes |
Basic Conversion Rules
Widget Types
JSONtype fields map to Stac + PascalCase class names:
| JSON Type | Dart Class |
|---|---|
text | StacText |
container | StacContainer |
column | StacColumn |
row | StacRow |
elevatedButton | StacElevatedButton |
scaffold | StacScaffold |
Action Types
JSONactionType fields map to Stac + PascalCase + Action:
| JSON actionType | Dart Class |
|---|---|
navigate | StacNavigateAction |
showDialog | StacDialogAction |
showSnackBar | StacSnackBarAction |
networkRequest | StacNetworkRequest |
setValue | StacSetValueAction |
Step-by-Step Migration
Step 1: Simple Widget
Before (JSON):Step 2: Widget with Properties
Before (JSON):Step 3: Nested Widgets
Before (JSON):Step 4: Actions
Before (JSON):Step 5: Complex Styles
Before (JSON):Common Patterns
Padding/Margin
JSON:Colors
| JSON | Dart |
|---|---|
"#FFFFFF" | StacColors.white |
"#000000" | StacColors.black |
"#2196F3" | StacColors.blue |
"#4CAF50" | StacColors.green |
"#F44336" | StacColors.red |
"primary" | 'primary' (theme color) |
Enums
JSON string values become Dart enums:| JSON | Dart |
|---|---|
"center" | StacMainAxisAlignment.center |
"spaceBetween" | StacMainAxisAlignment.spaceBetween |
"contain" | StacBoxFit.contain |
"cover" | StacBoxFit.cover |
Full Screen Migration Example
Before (JSON file:home_screen.json):
stac/home_screen.dart):
Build and Deploy
After migrating, build your Dart to JSON:stac/.build/.
Tips
- Start small: Migrate one screen at a time
- Use IDE features: Leverage autocompletion and error checking
- Run
stac buildoften: Catch errors early - Compare output: Verify generated JSON matches your expectations
- Keep JSON backups: Until you’re confident in your migration