Using a LayoutBuilder with Slivers - flutter

I use a layoutbuilder in flutter to create a responsive design. However, lately I've gotten into slivers and the layoutbuilder does not work with them by default. I've found a sliverlayoutbuilder class, but it does not appear to have the width I'm looking for.
What's the best way to get width when using slivers?

Related

which is the best technique for responsive flutter

creating responsive widget kinda isMobile?Fontsize 12 : fontsize 24 or use sizer package,what is the best responsive method for web,tablet,mobile?
flutter documentation did give some solution but , not effective for all purposes
AspectRatio
CustomSingleChildLayout
CustomMultiChildLayout
FittedBox
FractionallySizedBox
LayoutBuilder
MediaQuery
MediaQueryData
OrientationBuilder
if we using one by one , all methods have it's own defects .
mobile side and tablet side it will work , but in the case of windows and web , it won't.
if we combine these methods , also get some responsive issue , because of all methods are depend on the device height ,device width ,device aspectRatio , device Offset ,
also so much plugins are available but they have defects too , in the case of flutter_screenutil it depend on width , height . so if changes in one of the property it won't count. that means it won't change layout in web
so i am using this way combine 4 methods together
flutter_screenutil , LayoutBuilder , MediaQuery , AspectRatio
by using this way we can achieve,maintain the 3 layouts in one code
please use wisely according to your use case
the best place to find FLUTTER solutions/documentations is the official flutter/dart websites.
For this question:
Creating responsive and adaptive apps

which class or widget to use a better responsive layout in the flutter?

This class or widget is useful to create a responsive layout.
AspectRatio
CustomSingleChildLayout,
CustomMultiChildLayout,
FittedBox,
FractionallySizedBox,
LayoutBuilder,
MediaQuery,
MediaQueryData,
OrientationBuilder.
Which is to use the better responsive layout.
iDecode already told you that it all depends on what you need. here take a look at official documentation, https://flutter.dev/docs/development/ui/layout.
And here is my advice
Use row when you need Horizontal layout
Use column when you need Vertical layout
Use singleChildScrollView when you need scrolling layout
Use either GridView or listView when you need repetitive view
Use Expanded, Flexible, Limitedbox, flexiblebox for adjusting the size of the widget
Mine favourite : Rows for Horizontal, Column for vertical, Scrollview for Extra data exist in the page or UI not fitted in the screen, ListView for TableView UI etc
For best fitting layout: IS Expanded, AspectRatio

How can I get the height of a flutter widget?

How can I get the height of a flutter widget? I think it's using key, but I don't know how.
For example I want to get the height of a container, which will be in a stack to be able to put the padding of a list view and that at the initial moment it is under the container.
If you’re wanting to get the height before the children widget are built, use a LayoutBuilder widget to wrap the descendants.
Otherwise you can also check the dev tools by using the Select Wifget tool and looking at the widget”s properties

Flutter padding, margin and alginment best practices

What is the best practice in flutter for padding,margin etc.
example:
I made a simple drawer in flutter. To make everything to position in places I want. I used padding extensively.
Now the issue is when I test it on different phone of different size. the positions are inconsistent across different devices.
From the Flutter Docs:
Design discussion Why use a Padding widget rather than a Container
with a Container.padding property? There isn't really any difference
between the two. If you supply a Container.padding argument, Container
simply builds a Padding widget for you.
Container doesn't implement its properties directly. Instead,
Container combines a number of simpler widgets together into a
convenient package. For example, the Container.padding property causes
the container to build a Padding widget and the Container.decoration
property causes the container to build a DecoratedBox widget. If you
find Container convenient, feel free to use it. If not, feel free to
build these simpler widgets in whatever combination meets your needs.
In fact, the majority of widgets in Flutter are simply combinations of
other simpler widgets. Composition, rather than inheritance, is the
primary mechanism for building up widgets.
So, no worries about padding widgets.
A good practice to get some spaces inside a Column() or Row() is using SizedBox(). Then you add an extra space setting up width or height.

Differences between SliverList vs ListView in Flutter

What are the differences between SliverList and ListView in Flutter?
There's almost no difference.
ListView is a SliverList. Same with GridView, which is a SliverGrid.
They are doing exactly the same thing. The only difference between them is that SliverList is a sliver, not a widget. Which means it's used inside a ScrollView, usually CustomScrollView.
ListView is nothing else but a biding of SliverList to transform it into a Widget to make it usable alongside other widgets such as Row/Container.
Most of the time, use ListView.
But if you want advanced scroll behavior such as appbar animations with scroll ; you'll need to use a CustomScrollView. Which will force you to use SliverList instead of ListView.
According this article,
All of the scrollable views you use, like ListView and GridView,
are actually implemented using Slivers. You can kind of think of
Slivers as a lower-level interface, providing finer-grained control on
implementing scrollable area. Because slivers can lazily build each
item just as it scrolls into view, slivers are particularly useful for
efficiently scrolling through large numbers of children.