Skip to content

Instantly share code, notes, and snippets.

@hasanyatar
Last active July 19, 2023 11:26
Show Gist options
  • Save hasanyatar/e5d787c39ae276c2f6453f3faaa24e7b to your computer and use it in GitHub Desktop.
Save hasanyatar/e5d787c39ae276c2f6453f3faaa24e7b to your computer and use it in GitHub Desktop.
final CameraLensDirection initialCameraLensDirection = CameraLensDirection.back;
static List<CameraDescription> _cameras = [];
int _cameraIndex = -1;
@override
void initState() {
super.initState();
_initialize();
}
void _initialize() async {
if (_cameras.isEmpty) {
_cameras = await availableCameras();
}
for (var i = 0; i < _cameras.length; i++) {
if (_cameras[i].lensDirection == initialCameraLensDirection) {
_cameraIndex = i;
break;
}
}
if (_cameraIndex != -1) {
_startLiveFeed();
}
}
@override
void dispose() {
_stopLiveFeed();
super.dispose();
}
Future _stopLiveFeed() async {
await _controller?.stopImageStream();
await _controller?.dispose();
_controller = null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment