How to develop app for both device orientation(portrait and landscape) in flutter. When I rotate my device in landscape, app size will adjust on landscape. If I rotate my device in portrait, app size will adjust on portrait.
The answer is simple called as "responsive design", please have a look to one of the best post about the same subject ;
https://medium.com/flutter-community/developing-for-multiple-screen-sizes-and-orientations-in-flutter-fragments-in-flutter-a4c51b849434
and also from the original source from Flutter documentation ;
https://flutter.dev/docs/development/ui/layout/responsive
Hope this works
you can develop two widgets for each orientation each one has different sizes of text, padding.... using MediaQuery.of(context).orientation to get the current orientation or you can use Layout Builder.
Otherwise, you can lock your app to a specific orientation:
import 'package:flutter/services.dart';
main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
runApp(MyHomePage());
}
Related
My flutter app only supports portrait mode.
However, on one screen user can take the pic using the camera plugin. Users can take the pic portrait mode or landscape mode(Without changing device orientation).
I want to display a rectangle overlay on top of the camera. So if I can detect the mobile is in landscape or portrait mode I can add x,y, height, width values according to the orientation.
I am not asking about the Orientation builder because my app only supports portrait mode.
I have read some articles about Gyrometer to detect the device orientation. But in flutter, I haven't found code examples.
I am developer tizen consumer tv web app.How should i rotate the screen (toggle orientation) by code.
Please help us in this.
Let me know if you need any further information.
Lock the screen with the lockOrientation() method.
The following code snippet demonstrates how to lock the screen to a specified orientation.
screen.lockOrientation("portrait-secondary");
The method accepts the following parameter values: portrait-primary, portrait-secondary, landscape-primary, landscape-secondary, portrait, and landscape.
Note:
When using the screen orientation lock:
When the portrait value is used to lock the orientation, the orientation can change between portrait-primary and portrait-secondary. The landscape value behaves similarly.
Depending on the browser, unlocking the screen orientation may have no visual effect.
For more follow this.
You can use this code for rotate the device form Landscape to portrait .
b2bapis.b2bcontrol.setMenuOrientation("DEGREE_90",onSuccessSettingMenuOrientation,onErrorSettingMenuOrientation);
b2bapis.b2bcontrol.setSourceOrientation("TV","DEGREE_90", onSuccessSettingOrientation, onErrorSettingOrientation);
Note: need to add privileges in config.xml
I'm developing a game that runs on both mobile phones and tablets.
Currently I'm using only the Portrait orientation for all devices but the portrait orientation looks better on phones meanwhile landscape orientation looks better on tablets.
I set "Portrait" option in the Unity's Player Settings > Resolution and Presentation > Default Orientation but I would like to provide a landscape layout for tablets (without affecting phones).
How I can I do that? Is there any why to programmatically set the Screen orientation when the application starts?
You can try Screen.Orientation
In the Start (or Awake) method of a MonoBehaviour that is added to the stage call:
Screen.Orientation = ScreenOrientation.LandscapeRight
Now you just need to check if the device is tablet or phone, I don't know any way out of the box to do this, but you can check the aspect ratio and base your decision on this.
You can check the aspect ratio by getting Screen.width and Screen.height.
I'm using cordova 2.6 to make an iPhone application in Landscape mode only.
I've a problem with my splashscreen, when I launch app I see the good one during view seconds, then it rotate automatically before loading index page.
All params in plist, xcode and xml are on landscape mode, splashscreen has good size and all works fine on iPad. I know there is no landscape splashscreen for iPhone, I just want it still in portrait, don't rotate after view seconds.
As I can see problem is due to the splashscreen plugin of Cordova who create a view in the bad orientation after display the good splashscreen.
Thanks for your help
There is a bug in CordovaLib\Classes\CDVSplashScreen.m where it only switches out the images on an iPad for Landscape vs Portrait.
if you remove the line
} else if (CDV_IsIPad()) {
and the corresponding } then landscape will work across devices. You will need to ensure that your Resources\splash folder has the following files in it:
iPad:
Default-Portrait~ipad.png (768x1004px)
Default-Landscape~ipad.png (1024x748px)
iPad #2x:
Default-Portrait#2x~ipad.png (1536x2008px)
Default-Landscape#2x~ipad.png (2048x1496px)
iPhone:
Default-Portrait~iphone.png (320x480px)
Default-Landscape~iphone.png (480x320px)
iPhone #2x:
Default-Portrait#2x~iphone.png (640x960px)
Default-Landscape#2x~iphone.png (960x640px)
iPhone 5 #2x:
Default-568h-Portrait#2x~iphone.png (640x1136px)
Default-568h-Landscape#2x~iphone.png (1136x640px)
Hope that helps
i am developing an app which supports all orientations. i need to launch the splash screen (launching image) in all orientation types. but the project summary have only one field (portrait) to set the Default.png. how will i launch the landscape splash screen on my iphone app.
ipad have some features to setup both the orientations. is their anything like that in iphone,
thank you in advance
iPhone splash screen is only Portrait. iPad has landscape too because iPad home screen auto rotates unlike iPhone's.
In order to achieve such a behavior you can make your first screen identical to the splash screen ( add the same image on the background) . So it will look like a landscaped splash screen while you are loading the resources needed for your app but you can't start the app in landscape mode.
Hope this helps.
Cheers!
Nope, according to HIG, iPhone's default orientation is portrait and launch will do only portrait mode.
Let me quote a special behaviour
From Technical Note TN2244 Launching your iPhone Application in Landscape
Except for launch images used by the iPhone 6 Plus, asset catalogs assume that all iPhone launch images are for the portrait orientation.
Therefore
Launch images for iPhone apps are always sized to match the dimensions of the screen in portrait orientation. For applications that launch into landscape orientation, you should use your preferred graphics editing software to rotate the content of the launch image while keeping the image's size consistent with a portrait launch image (height > width).
if you don't do things correctly, you can end up with a blank/white screen
The result is a blank screen during launch as the system cannot find an appropriate launch image.
Unfortunately, the document was last updated 2 years ago.
2015-05-26 Updated for Xcode 6 and iOS 8.