You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The example includes a `Style Preset` dropdown and supports startup style selection:
245
288
@@ -248,12 +291,43 @@ cd example
248
291
flutter run --dart-define=STYLE_PRESET=midnight
249
292
```
250
293
294
+
You can also add a custom style at runtime:
295
+
296
+
- Click `Add Custom Style` and paste a style JSON object.
297
+
- Or boot with `CUSTOM_STYLE_JSON`:
298
+
299
+
```bash
300
+
cd example
301
+
flutter run \
302
+
--dart-define=STYLE_PRESET=sunset \
303
+
--dart-define=CUSTOM_STYLE_JSON='{"id":"aurora","base":"midnight","displayName":"Aurora","description":"Deep blue surface with bright cyan accents.","guidance":"Use high contrast and cool accent colors.","tokens":{"accent":"#22D3EE","panelBackground":"#0B1220","textPrimary":"#E0F2FE"}}'
This guide explains how to create custom styles for `flutter_json_render`.
4
+
5
+
## 1) Style Data Model
6
+
7
+
Use `JsonStyleDefinition` for style metadata and optional token payload.
8
+
9
+
```dart
10
+
const style = JsonStyleDefinition(
11
+
displayName: 'Aurora',
12
+
description: 'Deep blue surface with cyan accents.',
13
+
guidance: 'Use high contrast and cool color highlights.',
14
+
tokens: <String, dynamic>{
15
+
'accent': '#22D3EE',
16
+
'panelBackground': '#0B1220',
17
+
'textPrimary': '#E0F2FE',
18
+
},
19
+
);
20
+
```
21
+
22
+
## 2) Create Styles from JSON
23
+
24
+
```dart
25
+
final style = JsonStyleDefinition.fromJson(<String, dynamic>{
26
+
'displayName': 'Aurora',
27
+
'description': 'Deep blue surface with cyan accents.',
28
+
'guidance': 'Use high contrast and cool color highlights.',
29
+
'tokens': <String, dynamic>{
30
+
'accent': '#22D3EE',
31
+
'panelBackground': '#0B1220',
32
+
'textPrimary': '#E0F2FE',
33
+
},
34
+
});
35
+
```
36
+
37
+
`tokens` is intentionally open-ended so your renderer can define its own token contract.
38
+
39
+
## 3) Register Custom Styles
40
+
41
+
Single style:
42
+
43
+
```dart
44
+
final catalog = baseCatalog.withStyle('aurora', style);
45
+
```
46
+
47
+
Batch style import:
48
+
49
+
```dart
50
+
final catalog = baseCatalog.withStylesFromJson(<String, dynamic>{
51
+
'aurora': <String, dynamic>{
52
+
'displayName': 'Aurora',
53
+
'description': 'Deep blue surface with cyan accents.',
54
+
'guidance': 'Use high contrast and cool color highlights.',
55
+
'tokens': <String, dynamic>{
56
+
'accent': '#22D3EE',
57
+
'panelBackground': '#0B1220',
58
+
'textPrimary': '#E0F2FE',
59
+
},
60
+
},
61
+
'warm': <String, dynamic>{
62
+
'displayName': 'Warm',
63
+
'description': 'Cream cards with orange emphasis.',
64
+
'guidance': 'Use warm neutrals and soft border contrast.',
65
+
'tokens': <String, dynamic>{
66
+
'accent': '#EA580C',
67
+
'panelBackground': '#FFF7ED',
68
+
'textPrimary': '#7C2D12',
69
+
},
70
+
},
71
+
});
72
+
```
73
+
74
+
## 4) Prompting with Selected Style
75
+
76
+
```dart
77
+
final systemPrompt = catalog.prompt(
78
+
options: const JsonPromptOptions(
79
+
includeStyles: true,
80
+
selectedStyleId: 'aurora',
81
+
),
82
+
);
83
+
```
84
+
85
+
This makes LLM generation style-aware while still restricting output to your catalog.
86
+
87
+
## 5) Example App Runtime Injection
88
+
89
+
The example app supports runtime custom style injection with `CUSTOM_STYLE_JSON`:
90
+
91
+
```bash
92
+
cd example
93
+
flutter run \
94
+
--dart-define=STYLE_PRESET=sunset \
95
+
--dart-define=CUSTOM_STYLE_JSON='{"id":"aurora","base":"midnight","displayName":"Aurora","description":"Deep blue surface with bright cyan accents.","guidance":"Use high contrast and cool accent colors.","tokens":{"accent":"#22D3EE","panelBackground":"#0B1220","textPrimary":"#E0F2FE"}}'
96
+
```
97
+
98
+
You can also apply JSON from the in-app `Add Custom Style` dialog.
0 commit comments