Flutter/Dart - The getter 'path' was called on null. Receiver: null Tried calling: path
The getter 'path' was called on null.
This error means the the object for which you are writing object.path
is null
. You can use ?.
operator like this: object?.something
which is equivalent to:
object!=null ? object.something : null
You can pair it with ??
operator which you are already doing. So you only have to change your statement to:
String defaultaudio = _current?.path ?? 'http://example.com/ping.m4a';
Meggy
I'm a self-taught novice stumbling like a drunk through php, javascript, mysql, drupal and flutter.
Updated on December 23, 2022Comments
-
Meggy over 1 year
I'm using a playerWidget based on
flutter_audio_recorder
. Though it works as required I get an annoying error message error upon compiles and hot restarts because the path is null at first. The path is null because no audio files have yet loaded. But once thePageView.builder
which I'm using completes, the audio is then loaded so the error message has no effect on the actual operation. However the error message is becoming annoying. So I'd like to provide a default audio file from my server so the error will stop.The error message says
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ The following NoSuchMethodError was thrown building SpeakRecorder(dirty, dependencies: [_InheritedProviderScope<SocialProvider>], state: SpeakRecorderState#5e63d): The getter 'path' was called on null. Receiver: null Tried calling: path
And the Widget which calls the error is;
child: PlayerWidget(url: _current.path),
I tried the following;
String defaultaudio = _current.path ?? 'http://example.com/ping.m4a';
But it doesn't resolve the path is null error. Can anybody see what I'm doing wrong?
-
Ryosuke almost 4 yearsThe error means that
_current
isnull
whatever it is. You can instead write_current?.path ?? 'http://example.com/ping.m4a';
. -
Meggy almost 4 yearsThat did the trick! How can I can give you the credit? Can you answer the question formally?
-