Closed
Description
Problem
When the JsonSerializable class has a member which is a instance of a JsonSerializable class. It will a occur the following error.
[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'AccountState'
Code
app.dart
import 'package:meta/meta.dart';
import 'package:json_annotation/json_annotation.dart';
import 'account.dart';
part 'app.g.dart';
@JsonSerializable()
@immutable
class AppState extends Object with _$AppStateSerializerMixin {
final AccountState account;
AppState({
account,
}) : this.account = account ?? AccountState();
factory AppState.fromJson(Map<String, dynamic> json) =>
_$AppStateFromJson(json);
@override
String toString() => 'AppState${toJson()}';
@override
int get hashCode => account.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) || (other is AppState && account == other.account);
AppState copyWith({AccountState account}) => AppState(
account: account ?? this.account,
);
}
account.dart
import 'package:meta/meta.dart';
import 'package:json_annotation/json_annotation.dart';
import '../entity/user.dart';
import '../form/account.dart';
part 'account.g.dart';
@JsonSerializable()
@immutable
class AccountState extends Object with _$AccountStateSerializerMixin {
final UserEntity user;
final LoginFormData remeberedLogin;
AccountState({
user,
remeberedLogin,
}) : this.user = user ?? UserEntity(),
this.remeberedLogin = remeberedLogin ?? LoginFormData();
factory AccountState.fromJson(Map<String, dynamic> json) =>
_$AccountStateFromJson(json);
@override
String toString() => 'AccountState${toJson()}';
@override
int get hashCode => user.hashCode ^ remeberedLogin.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is AccountState &&
user == other.user &&
remeberedLogin == other.remeberedLogin);
AccountState copyWith({UserEntity user}) => AccountState(
user: user ?? this.user,
remeberedLogin: remeberedLogin ?? this.remeberedLogin,
);
}
Metadata
Metadata
Assignees
Labels
No labels