How to Adjust the screen to all android devices screens in flutter. I have checked in stackoverflow but unfortunately i haven't got any satisfying answer.


Solution 1: LGM

I think you have some questions about responsive layouts, so i will give you some examples with MediaQuery:

With MediaQuery you can get the device screen width:

    double width = MediaQuery.of(context).size.width; 

The height:

    double height = MediaQuery.of(context).size.height;

as well as the orientation:

    Orientation orientation = MediaQuery.of(context).orientation;

and also various information about the device, and then, you can base the layout on orientation, size etc.

Here's an example:

                 Container(
                    width: MediaQuery.of(context).orientation == Orientation.portrait ?
                      MediaQuery.of(context).size.width / 1.3 : MediaQuery.of(context).size.width / 2.1,
                    child: RaisedButton(
                        elevation: 0.0,
                        color: Colors.green,
                        child: Text("CONTINUE", style: TextStyle(color: Colors.white),),
                        onPressed: (){
                          //code of onPressed
                          );
                        }
                    ),
                  ),

You can use too Align, to define where the widget should be, Positioned, the properties of Column, Center etc.

One more example, using FittedBox to deal with texts:

   @override
   Widget build(BuildContext context) {
       return Material(
          child: SafeArea(
              child: Scaffold(
                  body: ListView(
                      children: <Widget>[
                      FittedBox(child: Text("Test"),),
                      FittedBox(child: Text("Flutter Flutter Flutter"),) 
                   ],
                 ),
              ),
            ),
         );
      }

The result:

Portrait:

Result1

Landscape:

Result2


Solution 2: Sukhi

Basically, Flutter automatically sets the height and width depending on the device sizes wherever possible. Example - if you have use a list view having 100 items then some devices may show 5 items at a time and some may show 6 items. It is automatically done by Flutter.

The problem comes only when you specify an absolute value for height and/or width. Let's say you've a widget and you specify width as 450. Now, it may fit on the bigger screens but on the small screen (e.g. width 400 points)then you'll see pixel overflow error in the UI.

Now, to solve this problem, you can use MediaQuery.of(context).size.height/width as suggested by LGM.