Can’t undersand what i’m doing wrong. audio_service library.
void initState() {
super.initState();
AudioHandler.mediaItem.value((MediaItem? item) {
setState(() {
_currentMediaItem = item;
});
});
}
issue: Instance member ‘mediaItem’ can’t be accessed using static access.
I can’t find anything about this in official documentation. In documentation of audio_service said what i need to identify variables as static. I was trying but can’t fix that.
2
Answers
Because
mediaItem
is a getter, and it’s not a static getter. This is why you get the error.The error you’re seeing is because you’re trying to access an instance member
mediaItem
as if it were a static member of theAudioHandler
class.Here’s how you can resolve the issue:
AudioHandler
: Instead of accessingmediaItem
as a static member, you should first get an instance ofAudioHandler
and then access itsmediaItem
member.Check the documentation: It’s possible that the documentation or the library might have been updated. Always ensure you’re looking at the latest version of the documentation and that your library is up-to-date.
Static members: If the documentation mentions marking variables as static, it typically means that those variables belong to the class itself and not to any particular instance of the class. However, in this case,
mediaItem
seems to be an instance member, so you should not be accessing it statically.