'Error Message: A nullable expression can't be used as a condition
How to fix this. Error message A nullable expression can't be used as a condition.
Try checking that the value isn't 'null' before using it as a condition.

This is my code.
floatingActionButton: FloatingActionButton(
onPressed: () => _webcamVideoElement.srcObject.active ? _webcamVideoElement.play() : _webcamVideoElement.pause(),
tooltip: 'Start stream, stop stream',
child: Icon(Icons.camera_alt),
),
);
}
Solution 1:[1]
Try this:
onPressed: () => _webcamVideoElement?.srcObject?.active ? _webcamVideoElement.play() : _webcamVideoElement.pause(),
Solution 2:[2]
It's pretty simple, before each property that can be null you should check null, try to click "Quick Fix" with Ctrl+. (Mac Command+.) to see what is suggested and that will probably fix it.
Also you didn't showed all your code, so I only can guess you are dealing with (VideoElement)[https://api.flutter.dev/flutter/dart-html/VideoElement-class.html] in that case your srcObject can (be null)[https://api.flutter.dev/flutter/dart-html/MediaElement/srcObject.html] in this case pretty close to what @Mohammad said, I suggest you to try this:
floatingActionButton: FloatingActionButton(
onPressed: () => _webcamVideoElement.srcObject?.active ? _webcamVideoElement.play() : _webcamVideoElement.pause(),
tooltip: 'Start stream, stop stream',
child: Icon(Icons.camera_alt),
),
);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mohammad |
| Solution 2 | Sávio Batista |
