Sanjib Sinha posted: " Photo by Jean-Baptiste Charrat on Unsplash Want to nest other scrolling views inside a scrolling widget? The answer is - NestedSCrollView. As the name suggests the NestedScrollView in flutter is nothing but a scrolling view at first sight. Howe"
Want to nest other scrolling views inside a scrolling widget?
The answer is - NestedSCrollView.
As the name suggests the NestedScrollView in flutter is nothing but a scrolling view at first sight. However, it has many advantages. And the main advantage is we can nest other scrolling views inside it.
Talking off scrolling views reminds us that in a common use case in any flutter app, we often use SliverAppBar containing a TabBar in the header and TabBarView in the body, inside NestedScrollView.
But we're not going to use that example here.
Because we have a plan to discuss TabBar and TabBarView in a separate flutter article. They deserve it.
Therefore let us concentrate on how we can use NestedScrollView widget in a different way. While doing so, we'll keep AppBar in our Scaffold widget, and SliverAppBar in NestedScrollView.
Besides we will also use CustomScrollView in the body of the NestedScrollView.
By the way, we must keep in mind that there are other scroll view widgets that help us to scroll. For instance, we can name ScrollView, which we'll definitely discuss in a separate post.
To start with, firstly let's get the full code snippet and start watching the screenshots, so that we can discuss the parts of the code along with the image of our flutter app.
In the above code we've set SliverAppBar pinned parameter true. As a result, we get these two screenshots when we run the app and after that when we scroll down to the down below.
Next, we scroll down to the end of the bottom screen and our SliverAppBar has collapsed totally, adjusts its size and the image disappears keeping only the text.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.