suragch / flutter_audio_service_demo

Companion project for Flutter audio_service tutorial
https://suragch.medium.com/background-audio-in-flutter-with-audio-service-and-just-audio-3cce17b4a7d?sk=0837a1b1773e27a4f879ff3072e90305
MIT License
57 stars 28 forks source link

Error when Importing to my Project #3

Closed gOzaru closed 3 years ago

gOzaru commented 3 years ago

Hello suragch. I tested your final project and it works and no error at all. But unfortunately when I imported your project into my project, there are errors everywhere especially the one with value. Like this file: audio_handler.dart lines 39 (Error on value)

playbackState.add(playbackState.value.copyWith(  <--- value is error here, very strange
        controls: [
          MediaControl.skipToPrevious,
          if (playing) MediaControl.pause else MediaControl.play,
          MediaControl.stop,
          MediaControl.skipToNext,
        ],

The error says: "The getter 'value' isn't defined for the type 'BehaviorSubject'. Try importing the library that defines 'value', correcting the name to the name of an existing getter, or defining a getter or field named 'value'."

I had done "Project Clean", but nothing happen. It still gives same error. I don't change any of your codes yet.
Any clue why this happen?

suragch commented 3 years ago

BehaviorSubject is part of rxdart, which audio_service uses. Are you using rxdart in your project already? There might be a conflict (that could be solved by using the same version of rxdart).

gOzaru commented 3 years ago

No, I haven't used any rxdart at all. Maybe I will try to add one version of rxdart.

gOzaru commented 3 years ago

Okay, now it works for all of them. I just need to add null check (!) after value. It seems I need to import rxdart.dart first in audio_handler.dart. Thank you once again for your help, suragch. God bless you. May you always be healthy and wealthy.

suragch commented 3 years ago

What version of audio_service are you using in pubspec.yaml? I had to had the ! In previous version but not in the most recent version.

gOzaru commented 3 years ago

audio_service: ^0.18.0-beta.0 The same one as written in your project.yaml I used Flutter 2.2.2.

suragch commented 3 years ago

Ok, that's strange then that value is nullable in your project but not in mine. My last guess would be to double check pubspec.lock.

gOzaru commented 3 years ago

I think some of them were lost when cleaning the project, especially image. Probably that was the cause?

suragch commented 3 years ago

I'm not sure. Let me know if you ever figure it out.

gOzaru commented 3 years ago

I used to leave it as empty for GetX version in pubspec.yaml. But today, I felt I had to add one in GetX. After I updated the GetX to the latest in pubspec.yaml, the errors show up in all null checks I put earlier. It forced me to remove all of them. After I removed them, there are no errors. Strange.