@@ -40,17 +40,13 @@ class _DocumentBuilderSectionTileState
40
40
final _pendingChanges = < DocumentChange > [];
41
41
42
42
bool _isEditMode = false ;
43
- bool _isValid = false ;
44
43
45
44
@override
46
45
void initState () {
47
46
super .initState ();
48
47
49
48
_editedSection = widget.section;
50
49
_builder = _editedSection.toBuilder ();
51
-
52
- // TODO(damian-molinski): validation
53
- _isValid = _editedSection.properties.every (_dummyValidation);
54
50
}
55
51
56
52
@override
@@ -61,9 +57,6 @@ class _DocumentBuilderSectionTileState
61
57
_editedSection = widget.section;
62
58
_builder = _editedSection.toBuilder ();
63
59
_pendingChanges.clear ();
64
-
65
- // TODO(damian-molinski): validation
66
- _isValid = _editedSection.properties.every (_dummyValidation);
67
60
}
68
61
}
69
62
@@ -86,7 +79,7 @@ class _DocumentBuilderSectionTileState
86
79
for (final property in widget.section.properties) ...[
87
80
const SizedBox (height: 8 ),
88
81
_PropertyBuilder (
89
- key: ObjectKey (property.schema.nodeId),
82
+ key: ValueKey (property.schema.nodeId),
90
83
property: property,
91
84
isEditMode: _isEditMode,
92
85
onChanged: _handlePropertyChange,
@@ -95,7 +88,7 @@ class _DocumentBuilderSectionTileState
95
88
if (_isEditMode) ...[
96
89
const SizedBox (height: 12 ),
97
90
_Footer (
98
- isValid: _isValid ,
91
+ isValid: _editedSection.isValid ,
99
92
onSave: _saveChanges,
100
93
),
101
94
],
@@ -127,20 +120,8 @@ class _DocumentBuilderSectionTileState
127
120
_builder.addChange (change);
128
121
_editedSection = _builder.build ();
129
122
_pendingChanges.add (change);
130
-
131
- // TODO(damian-molinski): validation
132
- _isValid = _editedSection.properties.every (_dummyValidation);
133
123
});
134
124
}
135
-
136
- bool _dummyValidation (DocumentProperty property) {
137
- final value = property.value;
138
- if (value is GroupedTagsSelection ) {
139
- return value.isValid;
140
- }
141
-
142
- return value != null ;
143
- }
144
125
}
145
126
146
127
class _Header extends StatelessWidget {
@@ -215,6 +196,7 @@ class _PropertyBuilder extends StatelessWidget {
215
196
@override
216
197
Widget build (BuildContext context) {
217
198
final definition = property.schema.definition;
199
+
218
200
switch (definition) {
219
201
case SegmentDefinition ():
220
202
case SectionDefinition ():
@@ -233,47 +215,44 @@ class _PropertyBuilder extends StatelessWidget {
233
215
case SingleLineHttpsURLEntryListDefinition ():
234
216
case NestedQuestionsListDefinition ():
235
217
case NestedQuestionsDefinition ():
236
- case SingleGroupedTagSelectorDefinition ():
237
- final value = property.value;
238
-
239
- final selection = value is GroupedTagsSelection
240
- ? value
241
- : const GroupedTagsSelection ();
242
-
243
- return SingleGroupedTagSelectorWidget (
244
- id: property.schema.nodeId,
245
- selection: selection,
246
- groupedTags: property.groupedTags (),
247
- isEditMode: isEditMode,
248
- onChanged: onChanged,
249
- isRequired: property.schema.isRequired,
250
- );
251
218
case TagGroupDefinition ():
252
219
case TagSelectionDefinition ():
253
220
case DurationInMonthsDefinition ():
254
221
case YesNoChoiceDefinition ():
255
222
case SPDXLicenceOrUrlDefinition ():
256
223
case LanguageCodeDefinition ():
257
- throw UnimplementedError ();
224
+ throw UnimplementedError ('${definition .type } not implemented' );
225
+ case SingleGroupedTagSelectorDefinition ():
226
+ final castProperty = definition.castProperty (property);
227
+ return SingleGroupedTagSelectorWidget (
228
+ id: castProperty.schema.nodeId,
229
+ selection: castProperty.value ?? const GroupedTagsSelection (),
230
+ groupedTags: definition.groupedTags (castProperty.schema),
231
+ isEditMode: isEditMode,
232
+ onChanged: onChanged,
233
+ isRequired: castProperty.schema.isRequired,
234
+ );
258
235
case AgreementConfirmationDefinition ():
236
+ final castProperty = definition.castProperty (property);
259
237
return AgreementConfirmationWidget (
260
- value: definition. castProperty (property) .value,
238
+ value: castProperty.value,
261
239
definition: definition,
262
- nodeId: property .schema.nodeId,
263
- description: property .schema.description ?? '' ,
264
- title: property .schema.title ?? '' ,
240
+ nodeId: castProperty .schema.nodeId,
241
+ description: castProperty .schema.description ?? '' ,
242
+ title: castProperty .schema.title ?? '' ,
265
243
isEditMode: isEditMode,
266
244
onChanged: onChanged,
267
245
);
268
246
case TokenValueCardanoADADefinition ():
247
+ final castProperty = definition.castProperty (property);
269
248
return DocumentTokenValueWidget (
270
- id: property .schema.nodeId,
271
- label: property .schema.title ?? '' ,
272
- value: property .value is int ? property.value ! as int : null ,
249
+ id: castProperty .schema.nodeId,
250
+ label: castProperty .schema.title ?? '' ,
251
+ value: castProperty .value,
273
252
currency: const Currency .ada (),
274
- range: property .schema.range ,
253
+ range: castProperty .schema.numRange ,
275
254
isEditMode: isEditMode,
276
- isRequired: property .schema.isRequired,
255
+ isRequired: castProperty .schema.isRequired,
277
256
onChanged: onChanged,
278
257
);
279
258
}
0 commit comments