cameraBottomMenu function

List<Widget> cameraBottomMenu({
  1. required CameraBits cameraBits,
  2. required Popper popper,
})

Implementation

List<Widget> cameraBottomMenu({
  required CameraBits cameraBits,
  required Popper popper,
}) {
  final ui = cameraBits.ui;

  void renameCamera(
    String label,
    CameraDescription camera,
  ) {
    ValidatingTextField.showDialog(
      ui: ui,
      title: const Text('Rename Camera'),
      initialValue: label,
      onSubmit: (value) {
        cameraBits.cameraNames.update(
          (m) => m[camera.name] = value,
        );
      },
    );
  }

  void selectCamera() {
    ui.showBottomSheet(
      (completer) => flcFrr(
        () {
          final cameraDescription = cameraBits.selectedCameraDescription();
          return flcBottomMenu([
            ...cameraBits.cameras.availableCameras().map((c) {
              return RadioListTile(
                value: c.name,
                groupValue: cameraDescription?.name,
                onChanged: (value) {
                  value?.let(cameraBits.selectedCameraName.set);
                },
                title: flcFrr(
                  () => Text(
                    cameraBits.watchCameraLabelOrFacing(c),
                  ),
                ),
              );
            }),
            if (cameraDescription != null)
              () {
                final label =
                    cameraBits.watchCameraLabelOrFacing(cameraDescription);
                return TextButton(
                  onPressed: () {
                    renameCamera(
                      label,
                      cameraDescription,
                    );
                  },
                  child: Text(
                    'Rename Camera: $label',
                    textAlign: TextAlign.center,
                  ),
                );
              }(),
          ]);
        },
      ),
      modalBarrierColor: Colors.black.withOpacity(0),
    );
  }

  return [
    TextButton(
      onPressed: () {
        popper.pop();
        selectCamera();
      },
      child: flcFrr(
        () => Text(
          'Camera: ${cameraBits.selectedCameraLabel() ?? '<none>'}',
          textAlign: TextAlign.center,
        ),
      ),
    ),
    TextButton(
      onPressed: () {
        popper.pop();
        flcShowResolutionMenu(
          ui: ui,
          resolution: cameraBits.resolution,
        );
      },
      child: 'Camera Resolution'.txt,
    )
  ];
}