From 1eb57af6fc471b9eaf123d85812d690a98afd737 Mon Sep 17 00:00:00 2001 From: Valeri Gokadze Date: Thu, 21 Mar 2024 12:24:25 +0400 Subject: [PATCH] Improved code (Playback icon button) --- lib/widgets/playback_icon_button.dart | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/widgets/playback_icon_button.dart b/lib/widgets/playback_icon_button.dart index 66e8d0ba6..e923ecc8d 100644 --- a/lib/widgets/playback_icon_button.dart +++ b/lib/widgets/playback_icon_button.dart @@ -14,19 +14,20 @@ Widget buildPlaybackIconButton( IconData icon; VoidCallback? onPressed; - if (processingState == AudioProcessingState.loading || - processingState == AudioProcessingState.buffering) { - icon = FluentIcons.spinner_ios_16_filled; - onPressed = null; - } else if (playing != true) { - icon = FluentIcons.play_circle_24_filled; - onPressed = audioHandler.play; - } else if (processingState != AudioProcessingState.completed) { - icon = FluentIcons.pause_circle_24_filled; - onPressed = audioHandler.pause; - } else { - icon = FluentIcons.replay_20_filled; - onPressed = () => audioHandler.seek(Duration.zero); + switch (processingState) { + case AudioProcessingState.buffering || AudioProcessingState.loading: + icon = FluentIcons.spinner_ios_16_filled; + onPressed = null; + break; + case AudioProcessingState.completed: + icon = FluentIcons.replay_20_filled; + onPressed = () => audioHandler.seek(Duration.zero); + break; + default: + icon = playing != true + ? FluentIcons.play_circle_24_filled + : FluentIcons.pause_circle_24_filled; + onPressed = playing != true ? audioHandler.play : audioHandler.pause; } return InkWell(