lockAndUnlockScreen method

Future<bool> lockAndUnlockScreen({
  1. required bool lock,
  2. double aspectRatio = 1.0,
})

Implementation

Future<bool> lockAndUnlockScreen(
    {required bool lock, double aspectRatio = 1.0}) async {
  if (lock) {
    if (aspectRatio <= 1.0) {
      await SystemChrome.setPreferredOrientations([
        DeviceOrientation.portraitUp,
        DeviceOrientation.portraitDown,
      ]);
      return true;
    } else {
      await SystemChrome.setPreferredOrientations([
        DeviceOrientation.landscapeRight,
        DeviceOrientation.landscapeLeft,
      ]);
      return true;
    }
  } else {
    await SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeRight,
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
    return true;
  }
}