Flutter – UI Orientation
All applications should be able to adjust their User Interface (UI) based on the orientation of the phone. By orientation, we implicate the portrait and landscape mode in smartphones rather the physical orientation. In, Flutter it is done so by using the OrientationBuilder, which determines the app’s current orientation. We will look into the same by building a simple application and change its orientation and display the UI changes.
Follow the below steps to build the application that changes UI based on the orientation of the phone:
- Create a GridView of 3 columns
- Use the OrientationBuilder to alter the number of columns.
Let’s discuss them in detail.
Create a GridView:
To create a GridView of 3 columns, use the code as shown below:
As discussed earlier, the orientationBuilder determines the orientation of the current application. We will design the Orientationbuilder in such a way that it displays 3 columns in portrait mode and 4 columns in landscape mode. to do so follow the below code:
The complete code would look like below: