I am a new Flutter learner. I am trying to write both mobile and web application using the same code base. I am wondering to know where should I use MediaQuery.of(context).size and where LayouBuilder( BoxConstraints constraints)?
Also like to know is it efficient to only one of them all through a big application or they are kind of complementary to each other?
EDIT: I like also know more about the behavior of these methods while
User zoom-in/zoom-out the screen
User changes the orientation of the screen on the mobile app, or the web browser size on the desktop computer
Which method is more suitable for these 2 situations?
LayoutBuilderprovide constrains based on its parent widget. You can wrapLayoutBuilderwith a SizedBox, then check the constraints of it.But for the
MediaQuery.of(context).sizeit will provide the screen size, doesnt matter it is wraped with a SizedBox or not.MediaQuery.of(context).size,The size of the media in logical pixels (e.g, the size of the screen).LayouBuilderFor size, you can use LayoutBuilder while the competent will be based on parent widget and it doesn't call the query. Somecases like on showDialog you need mediaQuery to get size. Use
LayoutBuilderwhenever possible.More about
LayoutBuilderand MediaQueryData/size