turnOff method

Future<MiniProgramFlashlightStatus> turnOff(
  1. String miniProgramId
)

Implementation

Future<MiniProgramFlashlightStatus> turnOff(String miniProgramId) async {
  _ensureActive();
  final owner = _ownerAppId;
  if (owner != null && owner != miniProgramId) {
    throw const MiniProgramFlashlightException(
      errorCode: MiniProgramErrorCodes.flashlightInUse,
      message: 'The flashlight is controlled by another mini-program.',
    );
  }
  if (owner == null) {
    final status = await getStatus();
    if (status.enabled) {
      throw const MiniProgramFlashlightException(
        errorCode: MiniProgramErrorCodes.flashlightInUse,
        message: 'The flashlight is controlled outside this mini-program.',
      );
    }
    return status;
  }
  final status = await provider.setEnabled(false);
  status.validate();
  _ownerAppId = null;
  return status;
}