LayoutBuilder and MediaQuerys - Flutter Explained

Поделиться
HTML-код
  • Опубликовано: 19 ноя 2024

Комментарии • 29

  • @nagarajjayabalan5032
    @nagarajjayabalan5032 4 года назад +4

    Well explained with examples. Clear voice. Thank your for this great video.

  • @Raimkhodzhanov
    @Raimkhodzhanov 7 дней назад

    Thank You, dear sir!

  • @sagarshah440
    @sagarshah440 3 года назад +2

    Ohh thank you so much for this video

  • @piiaall
    @piiaall 4 года назад +2

    Nicely explained.. 👌

  • @gamekonet
    @gamekonet 4 года назад +1

    amazing work and explanation, keep it up and best of luck

  • @tessertaha
    @tessertaha 4 года назад +2

    Great video, keep it up!

    • @FlutterExplained
      @FlutterExplained  4 года назад +1

      Thanks for your support! I will give my best :).

  • @darshang7133
    @darshang7133 3 года назад

    Hey, thank you for this great tutorial. It helped me a lot

  • @zukikazumi8965
    @zukikazumi8965 4 года назад +1

    thank u sir

  • @mohamedelyamani7845
    @mohamedelyamani7845 3 года назад +2

    How can we apply this on bigger app structure with complex widgets
    I can't duplicate the views one for portirat and one for landscape for the whole app widgets

    • @FlutterExplained
      @FlutterExplained  3 года назад +1

      That is a really good point, in some of my Live Streams I started by creating a "Responsive Widget" which allowed me to initialize it for 3 different screen sizes, with that I was able to use the same widgets with different information.
      FilledStacks created a fantastic series already with mutliple ways on how to implement a Responsive Architecture, maybe this will guide you along the way.
      www.filledstacks.com/tag/Responsive%20UI/

    • @mohamedelyamani7845
      @mohamedelyamani7845 3 года назад +1

      Thank you so much I already saw 3 videos I will follow his instructions

    • @FlutterExplained
      @FlutterExplained  3 года назад +1

      @@mohamedelyamani7845 Fantastic :) enjoy the journey!

  • @barsidemen5208
    @barsidemen5208 4 года назад +1

    Thank you, just a quick question regarding the orientation depending on the ternary in Scaffold. As HomeScreen widget is a stateless widget, how does it re-render when the device is switched from portrait to landscape?

    • @FlutterExplained
      @FlutterExplained  4 года назад +1

      That is related to the underling implementation of MediaQuery.of it uses the build method where it is inside as a reference (thanks to MediaQuery.of(context) it knows exactly in which widget it is inside. Therefore it can retrigger the rebuild as soon as it understands the changes. In the API it is not fully explained but you see that it is created with the intention that it triggers the rebuild.
      api.flutter.dev/flutter/widgets/MediaQuery-class.html
      I hope that helps :)

    • @barsidemen5208
      @barsidemen5208 4 года назад +2

      @@FlutterExplained Thanks, it does indeed. So, MediaQuery should be used with caution to prevent unnecessary rebuilds.

  • @ahmadramadan9806
    @ahmadramadan9806 11 месяцев назад

    Hello, your code about MediaQuery gave me an error "No MediaQuery widget ancestor found.", what is the reason for that

  • @GhostNikki
    @GhostNikki 4 года назад +1

    1 question buddy.
    What does constrain width return does it return it's parent widget width or screen width ?
    If I have Container its width is 200 and child is layoutbuilder so constraints.maxwidth will be 200?

    • @FlutterExplained
      @FlutterExplained  4 года назад

      Hi Nikhil, yes exactly. The constraints take the width and height of its parent widget, which in your case will be the Container widget with width 200.

  • @kaivalpatel3990
    @kaivalpatel3990 4 года назад +1

    Sir, So for like portrait and landscape we don't have any other class where it Automatically set the 5 cards with best fit? It would be hectic to design portrait and landscape for every Screen! Love from India!!

    • @FlutterExplained
      @FlutterExplained  4 года назад +1

      Good point unfortunately this is how flutter works I use in the Flutter website a Responsive Widget to make it possible to use the right widget depending on the situation.

    • @davidwhitaker6489
      @davidwhitaker6489 3 года назад

      Keep in mind everything in flutter can run in web so it will have some sort of common widget for things you'd like to do. Check out the flexible widget.

  • @coolprashantmailbox
    @coolprashantmailbox 4 года назад +1

    When should we use MediaQuery and LayoutBuilder in a screen

    • @FlutterExplained
      @FlutterExplained  4 года назад +1

      Hi Prashant Kumar, thanks for the question.
      The MediaQuery contains valuable information about the Orientation and the ScreenSize, and if you use the MediaQuery.of method, it retriggers the build method automatically again. Also, the MediaQuery can distinguish without returning a widget and, you can change only properties of font sizes.
      api.flutter.dev/flutter/widgets/MediaQuery-class.html
      The LayoutBuilder gives us additionally the BoxConstraints of the Widget it lives inside. Additionally, the LayoutBuilder needs necessarily to return a widget.
      api.flutter.dev/flutter/widgets/LayoutBuilder-class.html
      I hope that solved your question if not please feel free to DM me and I will try to give you a better explanation.

  • @Сова32
    @Сова32 4 года назад +2

    I made this differently
    SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
    ]);
    but I like your solution more, so I have to remake mine, thanks

    • @FlutterExplained
      @FlutterExplained  4 года назад

      I did it before I discovered the Media Queries orientation exactly in the same way :). It is easier to prototype I guess.