Commit 4cd223a7 authored by Collin Jackson's avatar Collin Jackson

Cancel timer when un-mounting date picker widget

parent d547103f
...@@ -299,12 +299,16 @@ class MonthPicker extends ScrollableWidgetList { ...@@ -299,12 +299,16 @@ class MonthPicker extends ScrollableWidgetList {
} }
DateTime _currentDate; DateTime _currentDate;
Timer _timer;
void _updateCurrentDate() { void _updateCurrentDate() {
_currentDate = new DateTime.now(); _currentDate = new DateTime.now();
DateTime tomorrow = new DateTime(_currentDate.year, _currentDate.month, _currentDate.day + 1); DateTime tomorrow = new DateTime(_currentDate.year, _currentDate.month, _currentDate.day + 1);
Duration timeUntilTomorrow = tomorrow.difference(_currentDate); Duration timeUntilTomorrow = tomorrow.difference(_currentDate);
timeUntilTomorrow += const Duration(seconds: 1); // so we don't miss it by rounding timeUntilTomorrow += const Duration(seconds: 1); // so we don't miss it by rounding
new Timer(timeUntilTomorrow, () { if (_timer != null)
_timer.cancel();
_timer = new Timer(timeUntilTomorrow, () {
setState(() { setState(() {
_updateCurrentDate(); _updateCurrentDate();
}); });
...@@ -332,6 +336,13 @@ class MonthPicker extends ScrollableWidgetList { ...@@ -332,6 +336,13 @@ class MonthPicker extends ScrollableWidgetList {
} }
return result; return result;
} }
void didUnmount() {
super.didUnmount();
if (_timer != null) {
_timer.cancel();
}
}
} }
// Scrollable list of years to allow picking a year // Scrollable list of years to allow picking a year
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment