Untitled
unknown
plain_text
a year ago
1.1 kB
3
Indexable
void switchCamera() async { CameraDescription newDescription; if (cameraController.description.lensDirection == CameraLensDirection.front) { newDescription = cameras.firstWhere((camera) => camera.lensDirection == CameraLensDirection.back); } else { newDescription = cameras.firstWhere((camera) => camera.lensDirection == CameraLensDirection.front); } if (cameraController != null) { await cameraController.dispose(); } cameraController = CameraController(newDescription, ResolutionPreset.medium); cameraController.initialize().then((_) { if (!mounted) return; setState(() {}); }); } IconButton( icon: Icon( Icons.flip_camera_ios_rounded, color: Colors.white, size: 25, ), highlightColor: Colors.blueAccent, onPressed: () async { switchCamera(); }, ),
Editor is loading...
Leave a Comment