How do I access an instance in a custom action... created in another custom action?

I’m stumped…

I’m using the audioplayers dart package to create and control multiple simultaneous audios.

I have all the state management and basic functions in there with no errors, but wasn’t getting any sound.

From my debugging, including just creating a single, non-dynamic player, it seems the issue is one of scope.

If this were javascript, it would just be as simple as throwing it into the global wondow. But I’m not clear how to do that with Dart.

Chatgpt debugging suggested adding something like what’s below in a custom file:

  AudioPlayer globalAudioPlayer = AudioPlayer();


But, there’s no obvious way to do that beyond going the github route.

I tried adding that as a custom action that loads with main(), but I’m still getting the error:

“Undefined name 'globalAudioPlayer'. Try correcting the name to one that is defined, or defining the name”

So, either there’s some way I need to define globalAudioPlayer in each custom action in a way that connects to the previously-created instance… or find a way to declare it in the global scope and import it into each custom action… or the github route? or….

Any advice?

Thanks!

5
1 reply