Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/widgets/app_circular_countdown_timer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class AppCircularCountDownTimer extends StatelessWidget {
final cs = Theme.of(context).colorScheme;

return CircularCountDownTimer(
key: const ValueKey('circular_timer'),
width: 250,
height: 250,
duration: duration,
Expand Down
6 changes: 6 additions & 0 deletions lib/widgets/timer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ class TimerState extends State<Timer> {
final _titleController = TextEditingController();
final _descriptionController = TextEditingController();

// A GlobalKey to ensure the timer display is preserved across orientation
// changes.

final _timerKey = GlobalKey();

////////////////////////////////////////////////////////////////////////
// SLEEP
////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -534,6 +539,7 @@ audio may take a little time to download for the Web version.
);

final timerDisplay = AppCircularCountDownTimer(
key: _timerKey,
duration: _duration,
controller: _controller,
onComplete: _complete,
Expand Down
61 changes: 61 additions & 0 deletions pr_description_74.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Pull Request Details

## Title

fix: preserve timer state across orientation changes (#74)

## Description

This PR resolves the issue where the meditation session timer would reset or
stop when the device orientation changed
(e.g., rotating a phone or resizing a window).

### Key Fixes

* **State Preservation**: Added a `GlobalKey` to the
`AppCircularCountDownTimer` in `lib/widgets/timer.dart`.
This ensures that the widget's internal state
(which tracks the active timer's progress) is preserved when
Flutter moves the widget between different positions in the tree
during an orientation change (Portrait Column vs Landscape Row).

* **Sub-Widget Stability**: Added a stable `ValueKey` to the internal
`CircularCountDownTimer` in
`lib/widgets/app_circular_countdown_timer.dart` to provide
additional stability during rebuilds.

* **Consistent UI**: The `TimerState` now correctly persists its local
configurations (duration, guided mode, etc.) throughout the
app's lifecycle during layout shifts.

## Related Issues

Fixes #74

## Type of Change

* [x] Bug fix (non-breaking change which fixes an issue)
* [ ] New feature (non-breaking change which adds functionality)
* [ ] Breaking change (fix or feature that would cause
existing functionality to not work as expected)
* [ ] This change requires a documentation update

## How To Test

1. Start an InnerPod session.

2. Rotate your device (or resize the window if on desktop/web) to switch
between portrait and landscape modes.

3. Observe that the timer continues its countdown from the current point
without resetting to the initial duration or stopping.

## Checklist

* [x] Changes adhere to the [style and coding guidelines](https://survivor.togaware.com/gnulinux/flutter-style.html)
* [x] I have performed a self-review of my code
* [x] I have commented my code, particularly in hard-to-understand areas
* [ ] I have made corresponding changes to the documentation
* [x] No lint check errors are related to these changes (`flutter analyze`)
* [x] All tests passed (`flutter test`)
* [x] Verified logic of state preservation across orientation.
Loading