Slivers in Flutter - Part (4)
SliverOpacity, SliverAnimatedOpacity, SliverFadeTransition, SliverVisibility, SliverIgnorePointer, SliverSafeArea.

I'm a mobile/web developer π¨βπ» who loves to build projects and share valuable tips for programmers
Follow me for Flutter, React/Next.js, and other awesome tech-related stuff π
- This is Part - 4 of Slivers in Flutter series. Make sure you check the first 3 parts.
- In this article, I'm going to explain some of the useful
Sliverwidgets, which are - SliverOpacity, SliverAnimatedOpacity, SliverFadeTransition, SliverVisibility, SliverIgnorePointer, SliverSafeArea.
SliverOpacity
- The
SliverOpacitymakessliverwidget transparent. - This works the same as the
Opacitywidget works forBoxwidgets. The difference is this only works on theSliverwidgets. - It usually takes values between
0.0to1.0. - For the value 0.0, the sliver child is simply not painted at all. For the value 1.0, the sliver child is painted immediately.
- For values of
opacityother than0.0and1.0, this class is relatively expensive because it requires painting the sliver child into an intermediate buffer. - Example :
- Output

SliverAnimatedOpacity
- If you see in the output of the above example, The opacity is directly jumping from
no visibilitytofull visiblity. It's not looking smooth. - To do the smooth transition between
0.0to1.0values we have to useSliverAnimatedOpacity. SliverAnimatedOpacityis an animated version ofSliverOpacitywhich automatically transitions the sliver child's opacity over a givendurationwhenever the given opacity changes.- ExampleOutput

SliverFadeTransition
- This also animates the
opacityof thesliverwidget. The only difference is it takesAnimation<double>value instead ofdoublevalues. - ExampleOutput :

- Here I've used
Curves.fastOutSlowInanimation. You can use any one of the curves defined in the below class:
SliverVisibility
SliverVisibilityis the same as theVisibilitywidget except it takessliveras a child.- It is used to show or hide a sliver child. When the
sliveris not visible thereplacementSliveris included instead. replacementSliveris used when thesliverchild is not visible, assuming that none of themaintainflags (in particular,maintainState) are set.SliverVisibilityhas different parameters like :- maintainAnimation : It is used to determine whether to maintain
animationswithin the sliver subtree when it is not visible. - maintainInteractivity: It is used to determine whether to allow the sliver to be interactive when hidden.
- maintainSemantics: It is used to determine whether to maintain the semantics for the sliver when it is hidden (e.g. for accessibility).
- maintainSize: It is used to determine whether to maintain space for where the sliver would have been.
- maintainState: It is used to determine whether to maintain the State objects of the sliver subtree when it is not visible.
- replacementSliver: Widget defined here is visible when sliver is not visible.
- Example:Output:

SliverIgnorePointer
- When you want your sliver to ignore the tapping or any kind of interaction then simply wrap your
sliverwidget insideSliverIgnorePointer. - It will disable the interaction of that widget.
- When
ignoringproperty istrue, the widget is not interactable. And whenignoringSemanticsproperty is true, the subtree will be invisible to the semantics layer - Example:Output:

SliverSafeArea
- If you've used
SafeAreathen,SliverSafeAreais also doing the same thing except it takessliveras a child instead ofBoxwidget. - For example, this will indent the sliver by enough to avoid the status bar at the top of the screen.
- It will also indent the sliver by the amount necessary to avoid The Notch on the iPhone X or other similar creative physical features of the display.Output:

Wrapping Up
- This is the 4th part of the
Slivers In Flutterseries. Check previous articles for more information about Slivers. - If you liked this article make sure to give a thumbs up π. Also share it with others if you found this helpfulπ.
- See you in the next article. Until then..






