I want the IconButton to change after onPressed () async {}. To ensure the player.play(); is started, I added an await statement. Once the button is pressed, I want the icon to change from Icons.play_arrow --> Icons.stop. so I have added a setState(() {});
I am expecting that once the player has started the setState will be executed.
However, the setstate is not executed, until the entire audio is played. which blocks the setstate from executing and therefore my page is not updated to show Icons.stop.
I am using:
just_audio: 0.9.36
just_audio_platform_interface: 4.2.2
Here is the code sample:
`I want the IconButton to change after onPressed () async {}. To ensure the player.play(); is started, I added an await statement. Once the button is pressed, I want the icon to change from Icons.play_arrow --> Icons.stop. so I have added a setState(() {});
I am expecting that once the player has started the setState will be executed.
However, the setstate is not executed, until the entire audio is played. which blocks the setstate from executing and therefore my page is not updated to show Icons.stop.
I am using:
just_audio: 0.9.36
just_audio_platform_interface: 4.2.2
Here is the code sample:
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: FlutterFlowTheme.of(context)
.primary),
),
child: IconButton(
icon: player.playing
? const Icon(Icons.stop)
: const Icon(Icons.play_arrow),
iconSize: 20,
color: FlutterFlowTheme.of(context)
.secondaryText,
onPressed: () async {
if (player.playing) {
await player.stop();
print('stop current player');
} else {
for (final otherPlayer
in allAudioPlayersList) {
if (otherPlayer != player &&
otherPlayer.playing) {
await otherPlayer.stop();
print(
' Stop other players before starting');
}
}
String mediaFile =
alertItemsListItem.mediaFileName;
if (isiOS) {
mediaFile += '.mp3';
}
await player.setAsset(
'assets/audios/$mediaFile');
print('state updated before playing');
await player.play();
print('after player started');
setState(() {});
print('after set state');
}
},
),
),
Print statements are there for me to see when certain commands are executed.
What am I missing. Is my understanding of how await should behave incorrect?