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

[BUG] I can't send list of strings #987

Closed
michaldev opened this issue Nov 6, 2020 · 4 comments
Closed

[BUG] I can't send list of strings #987

michaldev opened this issue Nov 6, 2020 · 4 comments

Comments

@michaldev
Copy link

I have problem with sending my list of strings to my server. I got an error:
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'

This is my code:

  @override
  Future<void> addPost(
      {String name, List<int> bytesFile, List<String> tags}) async {
    final data = FormData.fromMap({
      'file':
          await MultipartFile.fromBytes(bytesFile, filename: '${name}.bin'),
      'tags': tags,
      'name': name
    });
    await dio
        .post('$host/api/post',
            data: data,
            options: Options(headers: {'client-secret': clientSecret}))
        .catchError((onError) {
      throw CustomException(onError.error, onError.response.data);
    });
  }

Platform name: Flutter (Android)
Platform version: latest stable
Dio version: 3.0.10

@michaldev michaldev changed the title I can't send string list [BUG] I can't send string list Nov 6, 2020
@michaldev michaldev changed the title [BUG] I can't send string list [BUG] I can't send list of strings Nov 6, 2020
@michaldev
Copy link
Author

It looks like this: #633

@stale
Copy link

stale bot commented Dec 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Dec 19, 2020
@stale stale bot closed this as completed Dec 26, 2020
@abdalazeez1
Copy link

when i encode list like this
data['json_key'] = json.encode(listOfInt);///or something else String .....
now can send list
MapEntry(json_key: [1])

@patana93
Copy link
Contributor

In my case using json_serializable lib. I have resolved like this:


final jsonFile = MyModel.toJson();
    jsonFile['my_list_obj_field_on_db'] = json.encode(jsonFile["my_list_obj_field_on_db"]);
   
 final data = FormData.fromMap(jsonFile);

    final Response<Map<String, dynamic>> response;
    try {
      response = await _dio.post(path, data: data);
    } catch (err) {
    ... //other code
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants