Skip to content

A value of type 'List<dynamic>?' can't be assigned to a variable of type 'List<xxx>?' #3247

@dalton5

Description

@dalton5

Hi,

I use:

build_runner: ^2.1.7
json_serializable: ^6.1.4
json_annotation: ^4.4.0

In my code I have:

List<PlaceDto>? places;

And then when I run flutter pub run build_runner build --delete-conflicting-outputs

It generates in the .g file:

..places = json['places'] as List<dynamic>?

And I have the error:

A value of type 'List<dynamic>?' can't be assigned to a variable of type 'List<PlaceDto>?'.
Try changing the type of the variable, or casting the right-hand type to 'List<PlaceDto>?'.

But I can't change the generated code.

How can I fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions