-
-
Save hasanyatar/e5d787c39ae276c2f6453f3faaa24e7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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