Search code examples
flutterdartmedia-queries

How do I convert a specific pixel width/height to media query in flutter?


I would like to know if there is a calculation method to find out how much should be given in a media query width/height if I want a certain widget to have a specific amount of height/width pixel count. I do know how to use media query but I don't quite understand how we provide the value 'x' below:

Example - width: MediaQuery.of(context).size.width / x (I need this to be 40 pixels, how is this calculated)

Please let me know, thanks in advance!

 Container(
                  // I need to know how would I calculate it for 40 pixels exactly using Media query
                  width: 40,
                  height: 40,
                  decoration: BoxDecoration(color: Colors.red),
                )

Solution

  • You can use debugPrint(MediaQuery.of(context).size.width); to find out the screen size. Then you can calculate