availableCameras method

Future<List<CameraInfo>?> availableCameras()

获取可用摄像机 通常在第一次加载 Camera 后自动获取设备的可用相机,并且赋值给了cameras,所以后续可以不用再调用这个方法,可直接使用cameras

get available Cameras Generally, after the Camera is loaded for the first time, the controller automatically obtains the available cameras of the device and assigns the value to the cameras. Therefore, we can use the cameras directly instead of calling the method.

Implementation

Future<List<CameraInfo>?> availableCameras() async {
  try {
    final List<Map<dynamic, dynamic>>? cameras = await _channel
        .invokeListMethod<Map<dynamic, dynamic>>('availableCameras');
    if (cameras == null) return <CameraInfo>[];
    _cameras = cameras
        .map((Map<dynamic, dynamic> camera) => CameraInfo(
            name: camera['name'] as String,
            lensFacing: _getCameraLensFacing(camera['lensFacing'] as String)))
        .toList();
    return _cameras;
  } on PlatformException catch (e) {
    debugPrint(e.toString());
  }
  return null;
}