Audio Service displaying RED underline

Viewed 91

Recently I decided to up my skills by building an app with Audio features. so I came across these cool Dependencies just_audio and audio_service, but the usage of it is showing up errors and I can't figure out what is wrong.

Below is my code

import 'dart:async';

import 'package:audio_service/audio_service.dart';
import 'package:just_audio/just_audio.dart';

MediaControl playControl = MediaControl(
  androidIcon: 'drawable/ic_action_play_arrow',
  label: 'Play',
  action: MediaAction.play,
);
MediaControl pauseControl = MediaControl(
  androidIcon: 'drawable/ic_action_pause',
  label: 'Pause',
  action: MediaAction.pause,
);
MediaControl skipToNextControl = MediaControl(
  androidIcon: 'drawable/ic_action_skip_next',
  label: 'Next',
  action: MediaAction.skipToNext,
);
MediaControl skipToPreviousControl = MediaControl(
  androidIcon: 'drawable/ic_action_skip_previous',
  label: 'Previous',
  action: MediaAction.skipToPrevious,
);
MediaControl stopControl = MediaControl(
  androidIcon: 'drawable/ic_action_stop',
  label: 'Stop',
  action: MediaAction.stop,
);

class AudioPlayerTask extends BackgroundAudioTask {
  //
  var _queue = <MediaItem>[];
  int _queueIndex = -1;
  AudioPlayer _audioPlayer = new AudioPlayer();
  late AudioProcessingState _skipState;
  late bool _playing;
  bool get hasNext => _queueIndex + 1 < _queue.length;
  bool get hasPrevious => _queueIndex > 0;
  MediaItem get mediaItem => _queue[_queueIndex];

  late StreamSubscription<AudioPlaybackState> _playerStateSubscription;
  late StreamSubscription<AudioPlaybackEvent> _eventSubscription;

  @override
  void onStart(Map<String, dynamic> params) {
    super.onStart(params);
  }

  @override
  void onPlay() {}

  @override
  void onPause() {}

  @override
  void onSkipToNext() async {}

  @override
  void onSkipToPrevious() {}

  void skip(int offset) async {}
  @override
  Future<void> onStop() async {}

  @override
  void onSeekTo(Duration position) {}

  @override
  void onClick(MediaButton button) {}

  @override
  Future<void> onFastForward() async {}

  @override
  Future<void> onRewind() async {}

  _handlePlaybackComplete() {
    //
  }
}

Dependency of Interest

just_audio: ^0.9.7
audio_service: ^0.17.1
http: ^0.13.3

What am Getting

enter image description here

enter image description here

enter image description here

From the Above image, you will see that the following are underline in red colors AudioPlaybackState, void onStart(), void onPlay(), void onPause(), void onSkipToNext(), void onSkipToPrevious(), void onSeekTo(Duration position), void onClick(MediaButton button)

The Problem is that I can't import them into the code, taking for example AudioPlaybackState is not even among the list of keywords showing up

When I Hover my mouse around the Red Underline, i got the following

The name 'AudioPlaybackState' isn't a type so it can't be used as a type argument.

and got the following for each respective override when I hover around it

'AudioPlayerTask.onStart' ('void Function(Map<String, dynamic>)') isn't a valid override of 'BackgroundAudioTask.onStart' ('Future Function(Map<String, dynamic>?)').

What have done so far

  1. Have Upgrade my Flutter
  2. Invalidate and Restart
  3. Flutter Clean

Despite all that I have done, the issue still persists.

please what am not doing well?

1 Answers

After much googling, I found the right answer on a medium article post, here is the link Click here

My best guess is that after the upgrade in the dependencies most of the term was no longer used.

it's working now

Related