Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error with maxImage when set value more than 1 [only IOS] #22

Open
YouSour opened this issue Mar 23, 2022 · 5 comments
Open

error with maxImage when set value more than 1 [only IOS] #22

YouSour opened this issue Mar 23, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@YouSour
Copy link

YouSour commented Mar 23, 2022

hi , i got a problem with this package only on IOS when i set maxImages value more than 1 when i choose a image and then i got an error output like this :
Unhandled Exception: type 'String' is not a subtype of type 'List<dynamic>?' in type cast
any idea , pls share , thank in advance

@deandreamatias
Copy link
Contributor

Hi @YouSour!
Do you have a minimal code example of this?
Thanks!

@YouSour
Copy link
Author

YouSour commented Jul 13, 2022

@deandreamatias here
flutter_form_builder: ^7.1.1
form_builder_image_picker: ^2.0.0

import 'package:flutter_form_builder/flutter_form_builder.dart';

...

final _formKey = GlobalKey<FormBuilderState>();

...

@override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        FormBuilder(
          key: _formKey,
          autovalidateMode: AutovalidateMode.disabled,
          child: Column(
            children: <Widget>[
             FormBuilderImagePicker(
                      name: 'images',
                      decoration: CustomDecoration.formFieldDecoration(
                          label: 'Pick Photos'),
                      displayCustomType: (obj) =>
                          obj is ProductImageModel ? obj.filePath : obj,
                      valueTransformer: (List<dynamic>? images) {
                        return images?.map((image) {
                          return image is ProductImageModel
                              ? ProductImageModel(
                                      fileName: image.fileName,
                                      filePathFromDevice:
                                          image.filePathFromDevice,
                                      filePath: image.filePath)
                                  .toJson()
                              : ProductImageModel(
                                  fileName: XFileImage(file: image).file.name,
                                  filePathFromDevice:
                                      XFileImage(file: image).file.path,
                                ).toJson();
                        }).toList();
                      },
                      maxImages: 2,
                    ),

            ],
          ),
        ),
        Row(
          children: <Widget>[
            Expanded(
              child: MaterialButton(
                color: Theme.of(context).colorScheme.secondary,
                child: const Text(
                  "Submit",
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () {
                  _formKey.currentState!.save();
                  if (_formKey.currentState!.validate()) {
                    print(_formKey.currentState!.value);
                  } else {
                    print("validation failed");
                  }
                },
              ),
            ),
            const SizedBox(width: 20),
            Expanded(
              child: MaterialButton(
                color: Theme.of(context).colorScheme.secondary,
                child: const Text(
                  "Reset",
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () {
                  _formKey.currentState!.reset();
                },
              ),
            ),
          ],
        )
      ],
    );
  }

@deandreamatias
Copy link
Contributor

Thanks for sample code.
I'm working now in a update to Flutter 3 with PR #28
When I has time, I take a look to this bug.
Meanwhile, if other person or you want try fix this bug, I will apreciate

@deandreamatias deandreamatias added the bug Something isn't working label Jul 13, 2022
@YouSour
Copy link
Author

YouSour commented Jul 14, 2022

@deandreamatias ok, i appreciate that 😄

@mvarendorff
Copy link
Contributor

I could not reproduce this on a Simulator device with version 4.0.1 of this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants