renderProperty method

Iterable<Widget> renderProperty(
  1. BuildContext context,
  2. IMetaFormContext metaForm,
  3. HandledPaths paths,
  4. SunnyFormFieldState<List<IImageContent?>> state, {
  5. Key? key,
})
override

Renders a widget (or null) for a provided HandledPaths (see acceptProperties)

Implementation

Iterable<Widget> renderProperty(
    BuildContext context,
    IMetaFormContext metaForm,
    HandledPaths paths,
    SunnyFormFieldState<List<IImageContent?>> state,
    {Key? key}) {
  final fullPath = paths.fullPath<List<IImageContent>>();
  final form = context.form();
  final initialValue = form.path(fullPath);
  final readyCheck = state.form?.requestReadyCheck(fullPath);
  return [
    MediaGalleryControl<IImageContent>(
      size: 50,
      name: "$fullPath",
      initialValue: initialValue,
      progress: readyCheck,
      // readyCheck: readyCheck,
      allowThirdParty: true,
      onChanged: (files) {
        final imageContent = files;
        log.info(
            "Updating image lists: ${imageContent.map((e) => e.imageUrl).join()}");
        state.updateValue(imageContent, AttributeSource.control);
      },
      onError: (response, stack) {
        SunnyHud.error(context, "Problem uploading", duration: twoSeconds);
        log.warning("Error uploading: $response", response, stack);
        state.error = ValidationError.ofString(
          fullPath,
          "Problem uploading",
          debugMessage: "$response",
        );
      },
    )
  ];
}