-
Notifications
You must be signed in to change notification settings - Fork 19
Description
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?