The property 'audioStream' can't be unconditionally accessed because the receiver can be…
- User
The property 'audioStream' can't be unconditionally accessed because the receiver can be 'null'. The property 'trackName' can't be unconditionally accessed because the receiver can be 'null'.
class AudioPlayerWidget extends StatefulWidget{ final Track? track;
const AudioPlayerWidget({Key? key, this.track}) : super(key: key);
@override _AudioPlayerWidget createState() => _AudioPlayerWidget(); }
class _AudioPlayerWidget extends State { late AudioPlayer _audioPlayer; final bool _isPlaying = false;
@override void initState() { super.initState(); _audioPlayer = AudioPlayer(); }
@override void dispose() { _audioPlayer.dispose(); super.dispose(); }
void _togglePlayPause() { if (_isPlaying) { _audioPlayer.pause(); } else { _audioPlayer.play(UrlSource(widget.track.audioStream.toString())); } }
@override Widget build(BuildContext context) { return Container( height: 40, child: Column( children: [ Text(widget.track.trackName, style: const TextStyle(fontSize: 20)), IconButton( icon: Icon(_isPlaying ? Icons.pause : Icons.play_arrow), onPressed: _togglePlayPause, ), ], ), ); } }
- Assistant
- User
Как мне обработать событие в _togglePlayPause(), чтоб если track null, то кнопка была бы на паузе
- Assistant