Making Dynamic Layouts with Slivers in Dart's Flutter Framework

in #utopian-io6 years ago (edited)

flutter-logo.jpg

What Will I Learn?

  • You will learn what Slivers are and how to use them
  • You will learn about how Slivers compare to normal Box Widgets
  • You will learn about Sliver Delegates and how they can change Sliver behavior
  • You will learn how to use Custom Scroll View Widgets and Flexible Space Bar Widgets
  • You will learn about Sliver App Bar Widgets, Sliver Grid Widgets, Sliver Fill Viewport Widgets and Sliver Fixed Extent List Widgets
  • You will learn the difference between the Sliver Child Builder Delegate widget and the Sliver Child List Delegate.
  • You will also learn about Sliver Grid Delegates

Requirements

System Requirements:
OS Support for Flutter:
  • Windows 7 SP1 or later (64-bit)
  • macOS (64-bit)
  • Linux (64-bit)

Required Knowledge

  • A basic layouts and rendering
  • A fair understanding of Mobile development and Imperative or Object Oriented Programming
  • Basic understanding of box widgets

Resources for Flutter and this Project:

Sources:

Flutter Logo (Google): https://flutter.io/

Difficulty

  • Intermediate

Description

In this Flutter Tutorial, we look at the other main building block of the Flutter framework, Slivers. While Box Render widgets are static widgets based on constraints, the Sliver widgets are slivers of the viewport that can change dynamically in response to various different render events and variables.

Outline and Overview

Flutter widgets are generally grouped into two major types; Box Render widgets and Sliver Widgets. On one hand we have static widgets that build based off of a set of constraints which are passed down from their parents. On the other hand, we have widgets that can dynamically change based on various different build and render events. In this Flutter Video Tutorial, we take a look at the latter of these two, Sliver Widgets.

Outline for this Tutorial

Item 1: What is a Sliver?

A sliver widget is literally a sliver or slice of the viewport. Each sliver is laid out in such a way that they cover part of the viewport. Because they are based on the viewport rather then a set of static constraints; slivers can change their size, shape, and extent based on various events and offset changes.

scrollingbar.gif

In this Animated GIF, you can see how the Sliver App Bar widget changes in response to scrolling events. As it slides up, the title at the top and the bottom slide towards one another and the background image eventually disappears. Once you scroll out of view, the bar disappears all together.

Item 2: The Sliver Protocol

Each Sliver has a Sliver Constraints object which is used to create the Sliver Geometry Object. This Geometry object is what defines how the Sliver fits in the viewport. Slivers are defined by multiple dimensions which are used to describe the extent of the Sliver in relation to the Main Axis. Slivers are able to change their constraints based on non-linear events which allows them to have panning or scrolling effects.

grid.jpg

Here you can see the Sliver Grid that was used in our example application. The cross axis which is the horizontal axis is modified so that we can have three equal columns in this grid. The column sizes are determined based on the number of widgets in the grid, the spacing of these widgets along both the main and cross axis and the aspect ratio of these children widgets. The more columns we add to this grid, the smaller these children will become in response.

Item 3: Sliver Widgets and Delegates

As a result of having a dynamic layout, each Sliver Widget must be defined with a delegate. The delegate is what computes the resulting layout of the Sliver widget which allows us as developers to change how the widget will react to various events. More complex Slivers like the Sliver Grid widget have multiple delegates; a Grid Delegate and a normal Sliver Child Delegate.

sliver-grid.jpg

In this image, you can see the Sliver Grid widget. This widget uses both a grid delegate and a normal delegate. The grid delegate controls the size and position of the children in the sliver and the normal delegate creates the sliver which then uses the builder to layout its box children.

Project GitHub Repository:

The Source Code for this project can be found here

Video Tutorial

Projects and Series

Related Tutorials
Stand Alone Projects:
Building a Calculator
Movie Searcher Application

Minesweeper Game

Weather Application

Curriculum

![flutter-logo.jpg](https://steemitimages.com/DQmbFAKjCq1GWcT8qxs3NWXo5zJywJcVv9Eec35euxMs41F/flutter-logo.jpg)
Sort:  

Hey @tensor

We're already looking forward to your next contribution!

Decentralised Rewards

Share your expertise and knowledge by rating contributions made by others on Utopian.io to help us reward the best contributions together.

Utopian Witness!

Vote for Utopian Witness! We are made of developers, system administrators, entrepreneurs, artists, content creators, thinkers. We embrace every nationality, mindset and belief.

Want to chat? Join us on Discord https://discord.me/utopian-io

Thank you @tensor for your contribution. It has been reviewed and scored accordingly.

Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

Thank you for scoring my contribution.

You just received a Tier 0 upvote! Looking for bigger rewards? Click here and learn how to get them or visit us on Discord

Its funny how I was delegated to tier 0 despite the fact that I have consistently voted on the daily curator for the past 3-4 months. This is like the 3rd or 4th time this has happened. I think I am done with this service.

@tensor, you can contact them at Discord. They do admit sometimes there are mistakes, so if you inform them, they will adjust your tiers.

Hi, Thank you for you constant support for getting back to us.
Unfortunately tools and bots sometimes fail, that is why it is important to report all errors in vote counts so we can eliminate the as soon as possible.
We checked manually again and you have all the required votes to be on T2.
Sorry for the mistake. Please feel free to contact us on Discord when something like that happens.

I'm interested to see using Flutter for Steem Blockchain development. Do you have a similar tutorial?

I have some tutorials on things that could be adapter to the blockchain. Any tutorial that calls to an API would allow you to call to the steem API as well.

That's what I thought, thank you for responding to my question.

Its not a problem. If you have anymore, feel free to ask them.

I will try it. Thanks again.

Coin Marketplace

STEEM 0.27
TRX 0.13
JST 0.032
BTC 61763.08
ETH 2899.43
USDT 1.00
SBD 3.49