isLockScreenOrThrow function

Future<bool> isLockScreenOrThrow()

Returns whether the device is likely on the lock screen.

Throws IsLockScreenException when the plugin is missing, the platform returns null, or the platform call fails.

Implementation

Future<bool> isLockScreenOrThrow() async {
  try {
    final result = await _channel.invokeMethod<bool>('isLockScreen');
    if (result == null) {
      throw const IsLockScreenException(
        'null_result',
        'The platform returned null for isLockScreen.',
      );
    }
    return result;
  } on IsLockScreenException {
    rethrow;
  } on MissingPluginException catch (error) {
    throw IsLockScreenException(
      'missing_plugin',
      'The is_lock_screen2 plugin is not registered for this platform.',
      cause: error,
    );
  } on PlatformException catch (error) {
    throw IsLockScreenException(
      error.code,
      error.message ?? 'The platform failed to check the lock-screen state.',
      details: error.details,
      cause: error,
    );
  }
}