saDecrement method
- covariant Rocket sm,
- SamReq req
Handle action RK.saDecrement
The covariant keyword is used to inform Dart that sm
will be a subclass of
SamModel
and not SamModel
specifically.
Even though we are in the SamModel.present
execution scope we still need to use
sm.flipState()
to change the state so that any queued requests will be
handled properly.
The SamModel.setHot
is used to register the changes so that dependent widget builders get
properly notified a change has happened.
The Flutter timer used by this app automatically runs the first time but needs to be reset every time it expires. See prepReady.
Implementation
void saDecrement(covariant Rocket sm,SamReq req) {
if(sm.bLog)log("faDecrement $sm");
if (sm.isState([RK.ssCounting,RK.ssWaiting])) sm.setHot("ctr",(sm.getHot("ctr") as int) - 1);
int ctr = sm.getHot("ctr") as int;
if (ctr <= 0) {
sm.flipState(RK.ssLaunched);
} else {
if (sm.isState([RK.ssCounting,RK.ssWaiting])) sm._timer.reset();
if (sm.isState(RK.ssWaiting) && (ctr == 10)) sm.flipState(RK.ssCounting);
}
}