lockAndUnlockScreen method
The function lockAndUnlockScreen locks or unlocks the screen orientation based on the lock
parameter and the aspectRatio value.
Args: lock (bool): A boolean value indicating whether to lock or unlock the screen orientation. aspectRatio (double): The aspectRatio parameter is a double value that represents the aspect ratio of the screen. It is used to determine the preferred orientations when locking or unlocking the screen. If the aspect ratio is less than or equal to 1.0, the preferred orientations will be set to portrait mode. Otherwise, the. Defaults to 1.0
Returns: A boolean value is being returned.
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;
}
}