Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
A sliver is a part of a scrollable area that you may configure to behave differently. Slivers may be used to create bespoke scrolling effects such as elastic scrolling. Let’s learn how sliver works in flutter and how we can implement one. For better understanding, we have included some coding examples as well. Let’s dive right into it.
Flutter Sliver
A lower-level interface gives you complete freedom over how to construct a scrollable area. It comes in handy when scrolling through a significant number of child widgets in a scrollable area. Because they depend on the viewport, they can alter shape, size, and extent based on various events and offsets.
There are many kinds of slivers in a flutter, such as:
SliverAppBar
SliverList
SliverGrid
SliverPersistentHeader
SliverFixedExtentList
Before proceeding further, we need to know what a CustomScrollView is in Flutter.
CustomScrollView
Flutter's CustomScrollView is a scroll view that allows us to create various scrolling over effects, such as grids, lists, and extended headers. It features a sliver property that accepts a list of widgets like SliverAppBar, SliverFixedExtentList, SliverList, and SliverGrid, among others.
Using Slivers in Flutter
To implement Sliver, the entire content of the sliver’s segment must be placed inside a CustomScrollView regularly. Then we can condense the list of slivers to create the custom scrollable region.
Now, we need to understand each type of sliver.
SliverAppBar
SliverAppBar is a Flutter material design app bar that interfaces with a CustomScrollView. In general, it was the first child of CustomScrollView. It can change in height and float over the other scroll view widgets. It enables us to construct an app bar with different scrolling effects.
Let’s go through an example to have a better understanding.
Example
Let’s see how to use SilverAppBar with CustomScrollView
The SliverAppBar's essential attributes are as follows:
Action: This property is used to generate widgets that appear to the right of the appBar title. In general, it is an an iconButton that depicts common operations.
Leading: This attribute is used to specify a widget to the left of the title. It is typically used to position the Menu Drawer widget.
backgroundColor: This parameter is used to specify the color of the sliver app bar's background.
Title: The title of the SliverAppBar is defined by this attribute. It works similarly to the AppBar title in that it displays the name of the program.
bottom: This property is used to add space to the bottom of the title where we may define any widget we want.
expandedHeight: The maximum height of the app bar that may be expanded when scrolling is specified by this parameter. It must be expressed as a double value.
flexibleSpace: This attribute is used to define a widget that is layered behind the toolbar and tab bar. Its height is the same as the total height of the app bar.
floating:When the user scrolls towards the app bar, this property defines whether or not the app bar will be shown.
Sliver List
SliverList is a sliver that stores the children in a one-dimensional or linear array. It is necessary to use a delegate parameter to deliver the items in the list so that they will scroll into view. The children's list can be specified with a SliverChildListDelegate or built with a SliverChildBuilderDelegate.
SliverGrids arranges the children in a two-dimensional grid. It also employs a delegate or an explicit list to indicate the offspring, similar to the SliverList. However, it includes added formatting to the grid's cross-axis dimension. It allows you to set the grid layout in three ways:
Default Constructor
When a sliver grid displaying dynamic material retrieved from a database or an API is required.
A SliverFixedExtentList is a sliver that stores several children in a one-dimensional array or linear array with the same main-axis extent. It is more efficient than SliverList since no layouts on its children are required to derive the main-axis extent. It does not allow any separation between its children. Each kid must have the SliverConstraints. crossAxisExtent in the cross axis and itemExtent on the main axis
SliverPersistentHeader is a sliver that changes size as we scroll down.
Keeping the above statement in mind, the SliverPersistentHeader does not disappear when we scroll to the border of the viewport, which is opposed to the sliver's GrowthDirection. On the contrary, it changes size as we scroll.
The Container class in Flutter is a useful widget that combines standard widget painting, positioning, and scaling. A Container class may be used to store and move one or more widgets on the screen as needed. A container is simply a box that is used to store stuff.
What is a card in Flutter?
A card is a piece of paper that is used to represent information related to each other, such as an album, a physical location, contact information, and so on. In Flutter, a card has rounded corners and is shadowed. It was mainly used to save the content and actions of a single item.
What is CustomScrollView in flutter ?
Flutter's CustomScrollView is a scroll view that allows us to create various scrolling over effects, such as grids, lists, and extended headers. It features a sliver property that accepts a list of widgets like as SliverAppBar, SliverFixedExtentList, SliverList, and SliverGrid, among others.
Conclusion
In this blog, we extensively discussed the Slivers in Flutter and learned different components and attributes of Flutter Slivers along with some programming examples.
We hope that our blog enhances your knowledge regarding the Flutter Sliver.
If you think you are ready for the tech giants company, check out the mock test series on code studio.
You can also refer to our Guided Path on Coding Ninjas Studio to upskill yourself in domains like Data Structures and Algorithms, Competitive Programming, Aptitude, and many more!. You can also prepare for tech giants companies like Amazon, Microsoft, Uber, etc., by looking for the questions asked by them in recent interviews. If you want to prepare for placements, refer to the interview bundle. If you are nervous about your interviews, you can see interview experiences to get the ideas about these companies' questions.
Nevertheless, you may consider our premium courses to give your career an edge over others!
Do upvote our blogs if you find them helpful and engaging!