@@ -30,6 +30,7 @@ import 'package:musify/models/position_data.dart';
3030import 'package:musify/services/settings_manager.dart' ;
3131import 'package:musify/utilities/common_variables.dart' ;
3232import 'package:musify/utilities/flutter_bottom_sheet.dart' ;
33+ import 'package:musify/utilities/flutter_toast.dart' ;
3334import 'package:musify/utilities/formatter.dart' ;
3435import 'package:musify/utilities/mediaitem.dart' ;
3536import 'package:musify/utilities/utils.dart' ;
@@ -526,8 +527,9 @@ class NowPlayingPage extends StatelessWidget {
526527 showDialog (
527528 context: context,
528529 builder: (context) {
529- var hours = 0 ;
530- var minutes = 10 ;
530+ final duration = sleepTimerNotifier.value ?? Duration .zero;
531+ var hours = duration.inMinutes ~ / 60 ;
532+ var minutes = duration.inMinutes % 60 ;
531533 return StatefulBuilder (
532534 builder: (context, setState) {
533535 return AlertDialog (
@@ -537,7 +539,6 @@ class NowPlayingPage extends StatelessWidget {
537539 children: [
538540 Text (context.l10n! .selectDuration),
539541 const SizedBox (height: 16 ),
540-
541542 Row (
542543 mainAxisAlignment: MainAxisAlignment .spaceBetween,
543544 children: [
@@ -548,15 +549,27 @@ class NowPlayingPage extends StatelessWidget {
548549 icon: const Icon (Icons .remove),
549550 onPressed: () {
550551 if (hours > 0 ) {
551- setState (() => hours-- );
552+ setState (() {
553+ hours-- ;
554+ sleepTimerNotifier.value = Duration (
555+ hours: hours,
556+ minutes: minutes,
557+ );
558+ });
552559 }
553560 },
554561 ),
555562 Text ('$hours ' ),
556563 IconButton (
557564 icon: const Icon (Icons .add),
558565 onPressed: () {
559- setState (() => hours++ );
566+ setState (() {
567+ hours++ ;
568+ sleepTimerNotifier.value = Duration (
569+ hours: hours,
570+ minutes: minutes,
571+ );
572+ });
560573 },
561574 ),
562575 ],
@@ -574,15 +587,27 @@ class NowPlayingPage extends StatelessWidget {
574587 icon: const Icon (Icons .remove),
575588 onPressed: () {
576589 if (minutes > 0 ) {
577- setState (() => minutes-- );
590+ setState (() {
591+ minutes-- ;
592+ sleepTimerNotifier.value = Duration (
593+ hours: hours,
594+ minutes: minutes,
595+ );
596+ });
578597 }
579598 },
580599 ),
581600 Text ('$minutes ' ),
582601 IconButton (
583602 icon: const Icon (Icons .add),
584603 onPressed: () {
585- setState (() => minutes++ );
604+ setState (() {
605+ minutes++ ;
606+ sleepTimerNotifier.value = Duration (
607+ hours: hours,
608+ minutes: minutes,
609+ );
610+ });
586611 },
587612 ),
588613 ],
@@ -601,6 +626,7 @@ class NowPlayingPage extends StatelessWidget {
601626 final duration = Duration (hours: hours, minutes: minutes);
602627 if (duration.inSeconds > 0 ) {
603628 audioHandler.setSleepTimer (duration);
629+ showToast (context, context.l10n! .addedSuccess);
604630 }
605631 Navigator .pop (context);
606632 },
@@ -702,10 +728,27 @@ class NowPlayingPage extends StatelessWidget {
702728 iconSize: iconSize,
703729 onPressed: _lyricsController.flipcard,
704730 ),
705- IconButton .filledTonal (
706- icon: Icon (FluentIcons .timer_24_regular, color: _primaryColor),
707- iconSize: iconSize,
708- onPressed: () => _showSleepTimerDialog (context),
731+ ValueListenableBuilder <Duration ?>(
732+ valueListenable: sleepTimerNotifier,
733+ builder: (_, value, __) {
734+ return IconButton .filledTonal (
735+ icon: Icon (
736+ value != null
737+ ? FluentIcons .timer_24_filled
738+ : FluentIcons .timer_24_regular,
739+ color: _primaryColor,
740+ ),
741+ iconSize: iconSize,
742+ onPressed: () {
743+ if (value != null ) {
744+ audioHandler.cancelSleepTimer ();
745+ sleepTimerNotifier.value = null ;
746+ } else {
747+ _showSleepTimerDialog (context);
748+ }
749+ },
750+ );
751+ },
709752 ),
710753 ValueListenableBuilder <bool >(
711754 valueListenable: songLikeStatus,
0 commit comments