I'm building an app in flutter I've designed the UI and all but it's not responsive once I tilt the screen or change the type of device with device_preview the whole thing becomes a mess. I've checked out a couple of videos on youtube but it doesn't work. I need help


Solution 1: akash maurya

You can get orientation change by using

  1. OrientationBuilder widget, in this widget you will pass 'context' and 'orientation' then check orientation == Orientation.portrait for portrait mode and Orientation.landscape for landscape mode and build you UI base upon the check

    OrientationBuilder( builder: (context, orientation) { return Container( child:Text('any text'), height:orientation == Orientation.portrait) ? 'build portrait ui' : 'build landscape ui'; }, );

  2. or use MediaQuery.of(context).orientation == Orientation.portrait for portrait check and vice versa.