Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timer bug #728

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 0 additions & 2 deletions lib/app/modules/timer/controllers/timer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,3 @@ class TimerController extends FullLifeCycleController with FullLifeCycleMixin {
await createTimer();
}
}


280 changes: 126 additions & 154 deletions lib/app/modules/timer/views/timer_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _TimerAnimatedCardState extends State<TimerAnimatedCard>
widget.timer.startedOn, widget.timer.timerValue) <
widget.timer.timerValue &&
widget.timer.isPaused == 0) {
widget.timer.timeElapsed =widget.timer.timerValue-Utils.getDifferenceMillisFromNow(
widget.timer.timeElapsed = widget.timer.timerValue - Utils.getDifferenceMillisFromNow(
widget.timer.startedOn, widget.timer.timerValue);
IsarDb.updateTimerPauseStatus(widget.timer);
}
Expand All @@ -72,7 +72,7 @@ class _TimerAnimatedCardState extends State<TimerAnimatedCard>

@override
void dispose() {
_timerCounter!.cancel();
_timerCounter?.cancel();
super.dispose();
}

Expand All @@ -83,7 +83,7 @@ class _TimerAnimatedCardState extends State<TimerAnimatedCard>
horizontal: 10.0,
),
child: Container(
height: context.height / 3.0, // changed from 3.3 to 3.0
height: context.height / 3.0,
width: context.width,
child: Obx(
() => Card(
Expand Down Expand Up @@ -112,168 +112,140 @@ class _TimerAnimatedCardState extends State<TimerAnimatedCard>
),
Center(
child: Padding(
padding: const EdgeInsets.only(
left: 25.0,
right: 20.0,
top: 20.0,
bottom: 30.0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 3,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
widget.timer.timerName,
overflow: TextOverflow.ellipsis,
style: Theme.of(
context,
).textTheme.bodySmall!.copyWith(
fontWeight: FontWeight.w500,
color: kprimaryColor,
fontSize: 18),
),
),
Row(
children: [
IconButton(
onPressed: () {
setState(() {
if (_timerCounter != null &&
widget.timer.isPaused == 0) {
stopTimer();
}
widget.timer.timeElapsed = 0;
IsarDb.updateTimerTick(widget.timer);
if (_timerCounter != null &&
widget.timer.isPaused == 0) {
widget.timer.startedOn =
DateTime.now().toString();
IsarDb.updateTimerTick(widget.timer)
.then((value) => startTimer());
}
});
},
icon: Icon(
Icons.refresh,
size: 18,
color: Colors.white,
),
),
IconButton(
onPressed: () {
controller.stopRinger(
widget.timer.timerId);
controller.deleteTimer(
widget.timer.timerId);
},
icon: Icon(
Icons.close,
size: 18,
color: Colors.white,
),
),
],
),
],
),
Spacer(),
Padding(
padding:
const EdgeInsets.symmetric(vertical: 10),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
widget.timer.timerName,
overflow: TextOverflow.ellipsis,
// Set overflow property here
Obx(
() => AnimatedContainer(
duration: Duration(seconds: 1),
child: Text(
'${Utils.formatMilliseconds(widget.timer.timerValue - widget.timer.timeElapsed)}',
style: Theme.of(
context,
).textTheme.bodySmall!.copyWith(
fontWeight: FontWeight.w500,
color: kprimaryColor,
fontSize: 18),
),
Spacer(),
Padding(
padding: const EdgeInsets.only(right: 16.0),
child: InkWell(
onTap: () {
setState(() {
if (_timerCounter != null &&
widget.timer.isPaused == 0) {
stopTimer();
}
widget.timer.timeElapsed = 0;
IsarDb.updateTimerTick(widget.timer);
if (_timerCounter != null &&
widget.timer.isPaused == 0) {
widget.timer.startedOn =
DateTime.now().toString();
IsarDb.updateTimerTick(widget.timer)
.then((value) => startTimer());
}
});
},
child: Container(
decoration: BoxDecoration(
color: themeController.primaryBackgroundColor.value,
borderRadius:
BorderRadius.circular(20)),
child: const Padding(
padding: EdgeInsets.all(4.0),
child: Icon(
Icons.refresh,
size: 18,
),
).textTheme.displayLarge!.copyWith(
color: themeController.primaryTextColor.value,
fontSize: 44,
),
),
),
),
InkWell(
onTap: () {
controller
.stopRinger(widget.timer.timerId);
controller
.deleteTimer(widget.timer.timerId);
},
child: Container(
decoration: BoxDecoration(
color: themeController.primaryBackgroundColor.value,
borderRadius:
BorderRadius.circular(20)),
child: const Padding(
padding: EdgeInsets.all(4.0),
child: Icon(
Icons.close,
size: 18,
),
),
),
)
],
),
Padding(
padding:
const EdgeInsets.symmetric(vertical: 20),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Obx(
() => AnimatedContainer(
duration: Duration(seconds: 1),
child: Text(
'${Utils.formatMilliseconds(widget.timer.timerValue - widget.timer.timeElapsed)}',
style: Theme.of(
context,
).textTheme.displayLarge!.copyWith(
color: themeController.primaryTextColor.value,
fontSize: 44,
),
),
),
),
Padding(
padding: EdgeInsets.all(20),
child: GestureDetector(
onTap: () {
setState(() {
widget.timer.isPaused == 0
? stopTimer()
: startTimer();
widget.timer.isPaused =
widget.timer.isPaused == 0
? 1
: 0;
IsarDb.updateTimerPauseStatus(
widget.timer);
});
if (widget.timer.timeElapsed >=
widget.timer.timerValue) {
controller.stopRinger(
widget.timer.timerId);
setState(() {
widget.timer.timeElapsed = 0;
IsarDb.updateTimerTick(
widget.timer)
.then((value) => IsarDb
.updateTimerPauseStatus(
widget.timer));
widget.timer.isPaused = 1;
});
}
},
child: Container(
decoration: BoxDecoration(
color: kprimaryColor,
borderRadius:
BorderRadius.circular(80)),
width: 80,
height: 80,
child: Icon(
widget.timer.isPaused == 0
? Icons.pause
: Icons.play_arrow,
size: 30,
color: ksecondaryBackgroundColor,
),
),
))
],
),
),
GestureDetector(
onTap: () {
setState(() {
widget.timer.isPaused == 0
? stopTimer()
: startTimer();
widget.timer.isPaused =
widget.timer.isPaused == 0
? 1
: 0;
IsarDb.updateTimerPauseStatus(
widget.timer);
});
if (widget.timer.timeElapsed >=
widget.timer.timerValue) {
controller.stopRinger(
widget.timer.timerId);
setState(() {
widget.timer.timeElapsed = 0;
IsarDb.updateTimerTick(
widget.timer)
.then((value) => IsarDb
.updateTimerPauseStatus(
widget.timer));
widget.timer.isPaused = 1;
});
}
},
child: Container(
decoration: BoxDecoration(
color: kprimaryColor,
borderRadius:
BorderRadius.circular(80)),
width: 80,
height: 80,
child: Icon(
widget.timer.isPaused == 0
? Icons.pause
: Icons.play_arrow,
size: 30,
color:
Colors.white,
),
),
)
],
),
),
Spacer(),
],
),
),
Expand Down