在下面的肘节中,我试图保持应用程序的导航状态,但当杀死设备上的应用程序并返回到程序时,它返回到默认状态。我该如何解决这个问题?
我的腕尺是:
class NavigationCubit extends HydratedCubit<NavigationState> {
NavigationCubit() : super(NavigationState.empty);
@override
NavigationState fromJson(Map<String, dynamic> json) =>
NavigationState.fromJson(json);
@override
Map<String, dynamic> toJson(NavigationState state) => state.toJson();
}
州代码为:
@JsonSerializable()
class NavigationState {
final PagesTitle currentPage;
final PagesTitle targetPage;
const NavigationState({required this.currentPage, required this.targetPage});
Map<String, dynamic> toJson() => _$NavigationStateToJson(this);
factory NavigationState.fromJson(Map<String, dynamic> json) =>
_$NavigationStateFromJson(json);
static const NavigationState empty = NavigationState(
currentPage: PagesTitle.dashboard,
targetPage: PagesTitle.unknown,
);
}
enum PagesTitle { chart, payout, dashboard, profile, setting, unknown }
1条答案
按热度按时间eanckbw91#
尝试使用
HydratedMixin
而不是HydratedCubit