【发布时间】:2021-02-16 18:44:13
【问题描述】:
我正在尝试做一个 Redux 记录器。我是 Flutter 的新手。
我安装了redux_logging 包,但在我的情况下它只打印Instance of <NameOfClass>
至于我在this answer 中阅读的内容,我可以打印数据,但需要在课堂上使用 toJson 和 fromJson。就是这样,简化
@immutable
class FetchState {
final bool isError;
final bool isLoading;
FetchState({
this.isError,
this.isLoading,
});
factory FetchState.initial() => FetchState(
isLoading: false,
isError: false,
);
FetchState copyWith({
@required bool isError,
@required bool isLoading,
}) {
return FetchState (
isError: isError ?? this.isError,
isLoading: isLoading ?? this.isLoading
);
}
}
我如何以及在何处添加 toJson 和 fromJson 以便能够使用 json.encode(fetchState) 打印实例中的变量(我想 fetchState 是 FetchState 的一个实例)
谢谢
【问题讨论】: