From d59b473b5a599c1c0136f96f1bab891aee9d487b Mon Sep 17 00:00:00 2001 From: Japa Alekhin Llemos Date: Sun, 22 Sep 2019 03:31:06 +0800 Subject: [PATCH] added orientation aliases --- lib/util.dart | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/lib/util.dart b/lib/util.dart index dc7f4166e..665db1109 100644 --- a/lib/util.dart +++ b/lib/util.dart @@ -29,6 +29,62 @@ class Util { return SystemChrome.setPreferredOrientations([orientation]); } + /// Sets the preferred orientation of the app to landscape only. + /// + /// When it opens, it will automatically change orientation to the preferred one (if possible). + Future setLandscape() { + return SystemChrome.setPreferredOrientations([ + DeviceOrientation.landscapeLeft, + DeviceOrientation.landscapeRight, + ]); + } + + /// Sets the preferred orientation of the app to `DeviceOrientation.landscapeLeft` only. + /// + /// When it opens, it will automatically change orientation to the preferred one (if possible). + Future setLandscapeLeftOnly() { + return SystemChrome.setPreferredOrientations([ + DeviceOrientation.landscapeLeft, + ]); + } + + /// Sets the preferred orientation of the app to `DeviceOrientation.landscapeRight` only. + /// + /// When it opens, it will automatically change orientation to the preferred one (if possible). + Future setLandscapeRightOnly() { + return SystemChrome.setPreferredOrientations([ + DeviceOrientation.landscapeRight, + ]); + } + + /// Sets the preferred orientation of the app to portrait only. + /// + /// When it opens, it will automatically change orientation to the preferred one (if possible). + Future setPortrait() { + return SystemChrome.setPreferredOrientations([ + DeviceOrientation.portraitUp, + DeviceOrientation.portraitDown, + ]); + } + + /// Sets the preferred orientation of the app to `DeviceOrientation.portraitUp` only. + /// + /// When it opens, it will automatically change orientation to the preferred one (if possible). + Future setPortraitUpOnly() { + return SystemChrome.setPreferredOrientations([ + DeviceOrientation.portraitUp, + ]); + } + + /// Sets the preferred orientation of the app to `DeviceOrientation.portraitDown` only. + /// + /// When it opens, it will automatically change orientation to the preferred one (if possible). + Future setPortraitDownOnly() { + return SystemChrome.setPreferredOrientations([ + DeviceOrientation.portraitDown, + ]); + } + /// Waits for the initial screen dimensions to be available. /// /// Because of flutter's issue #5259, when the app starts the size might be 0x0.