flutter-form-builder-ecosystem / form_builder_image_picker

Images picker field for FlutterFormBuilder. Get images from gallery or camera
https://pub.dev/packages/form_builder_image_picker
BSD 3-Clause "New" or "Revised" License
33 stars 62 forks source link

How to convert XFile to MultipartFile #30

Closed tonypottera24 closed 2 years ago

tonypottera24 commented 2 years ago

I'm using form_builder_image_picker with Dio, which is a package that handles HTTP request. I'm wondering if there's any better way to case the XFile value given by form_builder_image_picker to MultipartFile (provided by Dio). I tried to accomplish this by using the valueTransformer as follows.

valueTransformer: (images) async {
  if (images != null) {
    var multipartFile = [];
    for (final image in images) {
      multipartFile.add(await MultipartFile.fromFile(image.path));
    }
    return multipartFile;
  }
},

However, since valueTransformer does not wait for future. I'll get List<Future> in the end. Does anyone have some advice?

tonypottera24 commented 2 years ago

https://github.com/flutter-form-builder-ecosystem/flutter_form_builder/issues/648

In here, flutter_form_builder team said that valueTransformer is built for type casting

deandreamatias commented 2 years ago

You can separated this logic from widget. Maybe create a state with ChangeNotifier or other solution

tonypottera24 commented 2 years ago

I see.