This commit is contained in:
@@ -20,12 +20,20 @@ class WorkoutSessionController extends _$WorkoutSessionController {
|
||||
final activities = _buildSequence(plan);
|
||||
ref.onDispose(() => _timer?.cancel());
|
||||
|
||||
final initialState = WorkoutSessionState(activities: activities);
|
||||
|
||||
if (activities.isNotEmpty) {
|
||||
final first = activities.first;
|
||||
return initialState.copyWith(timeRemaining: first.duration);
|
||||
if (activities.isEmpty) {
|
||||
return WorkoutSessionState(activities: activities);
|
||||
}
|
||||
|
||||
final first = activities.first;
|
||||
final initialState = WorkoutSessionState(
|
||||
activities: activities,
|
||||
timeRemaining: first.duration,
|
||||
);
|
||||
|
||||
if (first.isTimeBased) {
|
||||
Future.microtask(startTimer);
|
||||
}
|
||||
|
||||
return initialState;
|
||||
}
|
||||
|
||||
@@ -85,6 +93,19 @@ class WorkoutSessionController extends _$WorkoutSessionController {
|
||||
}
|
||||
}
|
||||
|
||||
void rewindSeconds(int amount) {
|
||||
final currentState = state.value;
|
||||
if (currentState == null) return;
|
||||
final maxDuration = currentState.currentActivity?.duration ?? 0;
|
||||
final newRemaining = (currentState.timeRemaining + amount).clamp(
|
||||
0,
|
||||
maxDuration,
|
||||
);
|
||||
state = AsyncValue.data(
|
||||
currentState.copyWith(timeRemaining: newRemaining),
|
||||
);
|
||||
}
|
||||
|
||||
void _tick(Timer timer) {
|
||||
if (state.value?.isFinished ?? true) return;
|
||||
var currentState = state.value!;
|
||||
@@ -98,7 +119,7 @@ class WorkoutSessionController extends _$WorkoutSessionController {
|
||||
if (newState.timeRemaining > 0) {
|
||||
newState = newState.copyWith(timeRemaining: newState.timeRemaining - 1);
|
||||
} else {
|
||||
state = AsyncValue.data(newState); // update interim state before next
|
||||
state = AsyncValue.data(newState);
|
||||
_goNext(newState);
|
||||
return;
|
||||
}
|
||||
@@ -123,7 +144,7 @@ class WorkoutSessionController extends _$WorkoutSessionController {
|
||||
|
||||
state = AsyncValue.data(newState);
|
||||
|
||||
if (nextActivity.isRest) {
|
||||
if (nextActivity.isTimeBased) {
|
||||
startTimer();
|
||||
} else {
|
||||
pauseTimer();
|
||||
@@ -152,23 +173,21 @@ class WorkoutSessionController extends _$WorkoutSessionController {
|
||||
|
||||
void jumpTo(int index) {
|
||||
final currentState = state.value;
|
||||
if (currentState != null &&
|
||||
index >= 0 &&
|
||||
index < currentState.activities.length) {
|
||||
final activity = currentState.activities[index];
|
||||
if (currentState == null) return;
|
||||
if (index < 0 || index >= currentState.activities.length) return;
|
||||
final activity = currentState.activities[index];
|
||||
|
||||
state = AsyncValue.data(
|
||||
currentState.copyWith(
|
||||
currentIndex: index,
|
||||
timeRemaining: activity.duration,
|
||||
),
|
||||
);
|
||||
state = AsyncValue.data(
|
||||
currentState.copyWith(
|
||||
currentIndex: index,
|
||||
timeRemaining: activity.duration,
|
||||
),
|
||||
);
|
||||
|
||||
if (activity.isRest) {
|
||||
startTimer();
|
||||
} else {
|
||||
pauseTimer();
|
||||
}
|
||||
if (activity.isTimeBased) {
|
||||
startTimer();
|
||||
} else {
|
||||
pauseTimer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user