renderProperty method
Iterable<Widget>
renderProperty(
- BuildContext context,
- IMetaFormContext metaForm,
- HandledPaths paths,
- SunnyFormFieldState state, {
- Key? key,
override
Renders a widget (or null) for a provided HandledPaths (see acceptProperties)
Implementation
@override
Iterable<Widget> renderProperty(
BuildContext context, IMetaFormContext metaForm, HandledPaths paths, SunnyFormFieldState<dynamic> state,
{Key? key}) {
final IMSchemaProperty? amountProp = paths.data[DurationProperty.amount] as IMSchemaProperty?;
final IMSchemaProperty? unitProp = paths.data[DurationProperty.unit] as IMSchemaProperty?;
// ignore: unused_local_variable
final basePath = paths.basePath;
final rawValue = state.value;
TimeSpan? initial;
if (rawValue is int) {
initial = TimeSpan(minutes: rawValue);
} else if (rawValue is TimeSpan) {
initial = rawValue;
} else if (rawValue == null) {
initial = TimeSpan(hours: 1);
} else {
initial = illegalState("Invalid type ${initial.runtimeType}");
}
return [
DurationPickerControl(
key: key,
onChange: (value) {
state.form!.set(unitProp!.jsonPath, TimeUnit.minutes_);
state.form!.set(amountProp!.jsonPath, value.minutes);
//state.updateValue(value, AttributeSource.control);
},
// amountAttribute: basePath + amountProp.jsonPath,
// unitAttribute: basePath + unitProp.jsonPath,
initialValue: initial, basePath: paths.path,
)
];
}