You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-14
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,7 @@ If you have any questions, feedback, or suggestions, feel free to reach out to m
56
56
-[Design a Prototype first](#design-a-prototype-first)
57
57
-[Hardcoded Sizes and Values](#hardcoded-sizes-and-values)
58
58
-[Builder vs MediaQuery](#builder-vs-mediaquery)
59
+
-[Why not just use `LayoutBuilder` and `OrientationBuilder`?](#why-not-just-use-layoutbuilder-and-orientationbuilder)
59
60
-[Conclusion](#conclusion)
60
61
61
62
## Introduction
@@ -262,22 +263,26 @@ Wrap the `popUntil` method within a `SchedulerBinding.instance.addPostFrameCallb
262
263
### Center ListView with whitespace
263
264
On larger screens, constraining the width of scrollable lists and centering them improves aesthetics and usability. Directly wrapping a `ListView` with a `ConstrainedBox` may restrict scrollable area to the constrained width, excluding the white space. A workaround involves using the `padding` parameter of `ListView` to dynamically calculate and apply horizontal padding based on screen size:

278
279
279
280
This approach uses again the `ScreenSize` enum to remain consistent.
280
281
282
+
**Why do we use `LayoutBuilder` instead of `MediaQuery`?**
283
+
Since we are showing the `NavigationRail` on larger screens, the `MediaQuery` would ignore the constrain from the `NavigationRail` and the `SafeArea`. So we use `LayoutBuilder` to get the actual constraints of the screen.
284
+
Read more in this section: [Builder vs MediaQuery](#builder-vs-mediaquery)
285
+
281
286
## Widgets
282
287
With our layout in place, it's time to explore the widgets that will enable us to construct a responsive UI. Flutter offers a rich set of widgets which are essential for creating responsive layouts and widgets. I strongly recommend reading documentation provided by the Flutter Team, which presents an extensive array of widgets in various formats. Here are some resources to get you started:
283
288
-**Flutter Docs:**
@@ -461,11 +466,14 @@ Avoid relying on hardcoded sizes and values within your app, as they frequently
461
466
Additionally, consider utilizing ConstrainedBox to introduce a degree of flexibility to your widgets. This approach allows you to set minimum and maximum constraints, providing your layout with the adaptability it needs to accommodate different screen sizes and orientations without compromising on design integrity.
462
467
463
468
### Builder vs MediaQuery
464
-
Using `LayoutBuilder` and `OrientationBuilder` can sometimes get a bit hacky to use especially when using them in combination or for complex layouts. That is why I prefer to use `MediaQuery`.
465
-
466
-
⚠️**Warning** There are few things you should keep in mind when using MediaQuery:
467
-
-`MediaQuery` comes with different methods like `sizeOf` or `orientationOf` which you should use instead of `MediaQuery.of(context).size` or `MediaQuery.of(context).orientation`. The reason you only want automatic rebuilds whenever that specific property changes.
468
-
- Using `MediaQuery` can have unwanted rebuilds. So make sure to only use it in a parent widget to define the whole Layout.
469
+
⚠️**Warning**`MediaQuery` should be used with caution:
470
+
-`MediaQuery` comes with different methods like `sizeOf` or `orientationOf` which you should use instead of `MediaQuery.of(context).size` or `MediaQuery.of(context).orientation`. The reason is you only want rebuilds whenever that specific property changes.
471
+
- Using `MediaQuery` can have unwanted rebuilds. So make sure to only use it in the very top of your Widget Tree to define the whole Layout.
472
+
-`MediaQuery` ignores paddings, SafeArea and other constraints because you get the size of the app window itself
473
+
- For child widgets you should use `LayoutBuilder` or `OrientationBuilder` to get the actual constraints for the widget
474
+
475
+
#### Why not just use `LayoutBuilder` and `OrientationBuilder`?
476
+
Using `LayoutBuilder` and `OrientationBuilder` can sometimes get a bit hacky to use especially when using them in combination for complex layouts. For that reason I prefer to use `MediaQuery`. But you could use `LayoutBuilder` and `OrientationBuilder` to get the same results.
469
477
470
478
## Conclusion
471
479
Our app now dynamically responds to every screen size. The beauty of Flutter is that it provides all the tools necessary for responsive design across any device.
0 commit comments