executeEnterDemoMode method
void
executeEnterDemoMode({
- required AFStateTestID stateTestId,
- required AFMergePublicStateDelegate mergePublicState,
inherited
Implementation
void executeEnterDemoMode({
required AFStateTestID stateTestId,
required AFMergePublicStateDelegate mergePublicState,
}) async {
// save the route state prior to moving to the transition screen.
final route = AFibF.g.internalOnlyActiveStore.state.public.route;
AFibF.g.setPreDemoModeRoute(route);
// first, navigate to the entering/leaving demo model page.
AFibF.g.internalOnlyDispatcher(AFConceptualStore.appStore).dispatch(AFUIDemoModeEnterScreen.navigatePush().castToReplaceAll());
// wait for all navigation to complete, so that you don't have animations trying to
// reference screens that existed prior to demo-mode, then:
// Note: you cannot use executeDeferredCallback here, because in prototype mode it doesn't actually delay,
// and we really need to delay and wait for the screen to render, even in prototype mode.
Timer(const Duration(seconds: 1), () {
// restore the demo mode store to its initial state.
final demoDispatcher = AFibF.g.internalOnlyDispatcher(AFConceptualStore.demoModeStore);
demoDispatcher.dispatch(AFResetToInitialStateAction());
AFibF.g.setActiveStore(AFConceptualStore.demoModeStore);
// build the test data.
final globalState = AFibGlobalState(
appContext: AFibF.context,
activeConceptualStore: AFConceptualStore.demoModeStore
);
globalState.initializeForDemoMode();
// find the desired state test.
final test = globalState.stateTests.findById(stateTestId);
// build that state test only.
final testContext = AFStateTestContextForState(
test as AFStateTest,
AFConceptualStore.demoModeStore,
isTrueTestContext: true
);
// this both generates the state, and configures all the query overrides,
test.execute(testContext);
// allow them to merge down any parts of the state that they wish to preserve from the real
// app (for example, the help state.)
AFibF.g.swapActiveAndBackgroundStores(
mergePublicState: mergePublicState
);
assert(AFibF.g.internalOnlyActive.store!.state.public.conceptualStore == AFConceptualStore.demoModeStore);
// this puts AFib into a mode where queries are routed through the state test's spoofed queries
// instead of through the true query handling mechanism.
//testContext.setTarget(AFTargetStore.uiStore);
AFibF.g.demoModeTest = testContext;
// now, you have the desired state, but you don't want to install all of it, so
// now, go ahead and synchronize
final route = AFibF.g.internalOnlyActiveStore.state.public.route;
AFibF.g.internalOnlyActiveDispatcher.dispatch(AFNavigateSyncNavigatorStateWithRoute(route));
});
}