Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SmartStruct issue generated with freezed #87

@namlxcntt

Description

@namlxcntt

Hi. I`m using Smartstruct create mapper from UserResponse -> UserModel

Version

smartstruct: ^1.4.0
smartstruct_generator: ^1.4.0
freezed_annotation: ^2.2.0
freezed: ^2.3.2

UserResponse class

`@freezed
class UserResponse with _$UserResponse {
const factory UserResponse(
{@jsonkey(name: 'id') String? id,
@jsonkey(name: 'name') String? name,
@jsonkey(name: 'phone') String? phone,
@jsonkey(name: 'email') String? email,
@jsonkey(name: 'birthday') String? birthday,
@jsonkey(name: 'avata') String? avatar,
@jsonkey(name: 'status') String? status,
@jsonkey(name: 'gender') String? gender}) = _UserResponse;

factory UserResponse.fromJson(Map<String, dynamic> json) => _$UserResponseFromJson(json);
}
`

UserModel class

@freezed class UserModel with _$UserModel { const factory UserModel( {String? id, String? name, String? phone, String? email, String? birthday, String? avatar, String? status, String? gender}) = _UserModel; }

Finally class Mapper

`part 'user_mapper.mapper.g.dart';

@Mapper()
abstract class UserMapper {
@mapping(
target: 'copyWith',
ignore: true) // drawback as freezed generates a getter for the copyWith, and we have no way of determining that the copyWith shouldn't be mapped without explicitly ignoring it
UserModel fromModel(UserResponse model);
}
`

Build error -> Bad state: No element

I'm looking for help, is there anyone who can help me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions