Error: Null check operator used on a null value
Closed this issue · 2 comments
After setting up using the example, I can see that the audio/video stream has been joined via the console but on the UI, it is returning Failed: Error: Null check operator used on a null value.
Note: When I copied the MeetingSessionCreator file, it returned an error and I had to make the return value Future<String?> instead of the default Future for it to run at all.
It was caused by null operators used on the results coming from calling the methods.
For example:
Future<void> _audioVideoStopRemoteVideo() async {
String result;
try {
result = (await Chime.audioVideoStopRemoteVideo())!;
} on PlatformException catch (e) {
result = 'AudioVideoStopRemoteVideo failed: PlatformException: $e';
} catch (e) {
result = 'AudioVideoStopRemoteVideo failed: Error: $e';
}
if (mounted) {
setState(() {
_audioVideoStartRemoteVideoResult = result";
});
}
}
This will give you null operator errors due to String not being a nullable string and the null operator used at the end of the line where the Chime.audioVideoStopRemoteVideo() is called.
Instead, make the String nullable first and remove the null operator.
Also while setting the result, check for null as it means success.
Here is the Correct code:
Future<void> _audioVideoStopRemoteVideo() async {
String? result;
try {
result = (await Chime.audioVideoStopRemoteVideo());
} on PlatformException catch (e) {
result = 'AudioVideoStopRemoteVideo failed: PlatformException: $e';
} catch (e) {
result = 'AudioVideoStopRemoteVideo failed: Error: $e';
}
if (mounted) {
setState(() {
_audioVideoStartRemoteVideoResult = result ?? "Remote video end successful";
});
}
}
You will need to do this for all areas where such is applicable.
Thanks for your report!
I fixed the example now.