From 7e6aaf40c486a7f568c4aa4a2fa916a20d9f237b Mon Sep 17 00:00:00 2001 From: David Senk Date: Mon, 23 Sep 2024 16:46:43 -0400 Subject: [PATCH] add loading indicator for better ux --- lib/Listen.dart | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/Listen.dart b/lib/Listen.dart index ab5ad1e..f48186c 100644 --- a/lib/Listen.dart +++ b/lib/Listen.dart @@ -36,6 +36,8 @@ class _PlayControlsState extends State @override bool get wantKeepAlive => true; + bool _isLoading = false; + final ListenHandler _listenHandler = getListenHandlder(); @override @@ -46,7 +48,11 @@ class _PlayControlsState extends State _listenHandler.playbackState.listen((PlaybackState state) { print("Playback state changed"); - setState(() {}); + setState(() { + //if state changed, we're no longer loading! + //doesn't matter if we're playing or not! + _isLoading = false; + }); }); } @@ -76,14 +82,26 @@ class _PlayControlsState extends State child: InkWell( splashColor: Theme.of(context).colorScheme.onPrimaryContainer, onTap: () async { + if (_isLoading) { + //skip doing anything else if we're still loading... + return; + } await playPause(); - setState(() {}); + setState(() { + if (!_listenHandler.isPlaying()) { + _isLoading = true; + } + }); }, child: SizedBox( width: 100, height: 100, child: Icon( - _listenHandler.isPlaying() ? Icons.stop : Icons.play_arrow, + _isLoading + ? Icons.hourglass_empty + : _listenHandler.isPlaying() + ? Icons.stop + : Icons.play_arrow, color: Colors.white, size: 50, ),