add loading indicator for better ux
This commit is contained in:
@@ -36,6 +36,8 @@ class _PlayControlsState extends State<PlayControls>
|
|||||||
@override
|
@override
|
||||||
bool get wantKeepAlive => true;
|
bool get wantKeepAlive => true;
|
||||||
|
|
||||||
|
bool _isLoading = false;
|
||||||
|
|
||||||
final ListenHandler _listenHandler = getListenHandlder();
|
final ListenHandler _listenHandler = getListenHandlder();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -46,7 +48,11 @@ class _PlayControlsState extends State<PlayControls>
|
|||||||
|
|
||||||
_listenHandler.playbackState.listen((PlaybackState state) {
|
_listenHandler.playbackState.listen((PlaybackState state) {
|
||||||
print("Playback state changed");
|
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<PlayControls>
|
|||||||
child: InkWell(
|
child: InkWell(
|
||||||
splashColor: Theme.of(context).colorScheme.onPrimaryContainer,
|
splashColor: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
if (_isLoading) {
|
||||||
|
//skip doing anything else if we're still loading...
|
||||||
|
return;
|
||||||
|
}
|
||||||
await playPause();
|
await playPause();
|
||||||
setState(() {});
|
setState(() {
|
||||||
|
if (!_listenHandler.isPlaying()) {
|
||||||
|
_isLoading = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 100,
|
height: 100,
|
||||||
child: Icon(
|
child: Icon(
|
||||||
_listenHandler.isPlaying() ? Icons.stop : Icons.play_arrow,
|
_isLoading
|
||||||
|
? Icons.hourglass_empty
|
||||||
|
: _listenHandler.isPlaying()
|
||||||
|
? Icons.stop
|
||||||
|
: Icons.play_arrow,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
size: 50,
|
size: 50,
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user