Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.1 kB
1
Indexable
Never
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();
                        },
                      ),
Leave a Comment