Untitled
unknown
plain_text
2 years ago
1.1 kB
5
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