showUnifiedDialog<T> function
- required BuildContext context,
- required WidgetBuilder builder,
- bool barrierDismissible = true,
- LibraryScreenState? libraryState,
Shows a unified dialog that handles focus and timer state
Implementation
Future<T?> showUnifiedDialog<T>({
required BuildContext context,
required WidgetBuilder builder,
bool barrierDismissible = true,
LibraryScreenState? libraryState,
}) async {
final timerController = Get.find<ExerciseTimerController>();
final overlayManager = GlobalExerciseOverlay();
final dashboard =
libraryState ?? context.findAncestorStateOfType<LibraryScreenState>();
if (dashboard?.searchHasFocus == true) {
dashboard?.wasSearchFocusedBeforeNavigation = true;
} else {
dashboard?.wasSearchFocusedBeforeNavigation = false;
}
dashboard?.forceRedirectFocus();
if (dashboard?.searchHasFocus == true) {
dashboard?.wasSearchFocusedBeforeNavigation = true;
} else {
dashboard?.wasSearchFocusedBeforeNavigation = false;
FocusManager.instance.primaryFocus?.unfocus();
}
// Stop the timer if it is running
final wasRunning =
timerController.isRunning.value && !timerController.isPaused.value;
if (wasRunning) {
timerController.pause();
timerController.autoPaused.value = true;
}
overlayManager.setDialogOpen(true);
final result = await showDialog<T>(
context: context,
barrierDismissible: barrierDismissible,
builder: builder,
);
overlayManager.setDialogOpen(false);
// If the timer was paused due to showing the dialog, we resume it
if (timerController.autoPaused.value) {
timerController.resume();
timerController.autoPaused.value = false;
}
// If the timer was running before showing the dialog, we resume it
dashboard?.handleReturnedFromExercise();
return result;
}