availableCameras method

  1. @override
Future<List<CameraDescription>> availableCameras()

Completes with a list of available cameras.

This method returns an empty list when no cameras are available.

Implementation

@override
Future<List<CameraDescription>> availableCameras() async {
  try {
    final List<Map<dynamic, dynamic>>? cameras =
        await _channel.invokeListMethod<Map<dynamic, dynamic>>('availableCameras');

    if (cameras == null) {
      return <CameraDescription>[];
    }

    return cameras.map((Map<dynamic, dynamic> camera) {
      return CameraDescription(
        name: camera['name']! as String,
        lensDirection: parseCameraLensDirection(camera['lensFacing']! as String),
        sensorOrientation: camera['sensorOrientation']! as int,
      );
    }).toList();
  } on PlatformException catch (e) {
    throw CameraException(e.code, e.message);
  }
}