Using Tab and Scroll Controllers and The Nested Scroll View in Dart's Flutter Framework

flutter-logo.jpg

Repository

https://github.com/flutter/flutter

What Will I Learn?

  • You will learn about Scroll Controllers in Flutter
  • You will learn about Tab Controllers in Flutter
  • You will learn how to animate and automate scrolling and tabbing
  • You will learn about the NestedScrollView widget
  • You will learn how to use Slivers to create dynamic scrolling widgets

Requirements

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

Required Knowledge

  • A little understanding of animation
  • Some understanding of navigation
  • A fair understanding of Mobile development and Imperative or Object Oriented Programming

Resources for Flutter and this Project:

Sources:

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

Difficulty

  • Intermediate

Description

Outline and Overview

In this Flutter Video Tutorial, we take a look at some of the more advanced concepts of the Scroll and Tab controller objects. We also take a look at the NestedScrollView widget; which allows us to safely embed multiple scrolling widgets into one another. We look at the SliverAppBar widget once again but this time we create our own scaffold with it. We also look at the jumpTo and animateTo methods on the controllers and how they can automate the movement between tabs and the scrolling of views.

Outline for this Tutorial
Controlling Movement and Animations with Controllers

Controllers are a central concept in the Flutter Framework and they are used in many design patterns in programming in general. Controllers are objects that allow the developer to programmatically interact with the actions of widgets. The controllers that we focus on in this tutorial are the TabController and the ScrollController.

initState-control.png

In this image, you can see the initState for our main state object in this application. We use this function to instantiate the two controllers. For the TabController, we need to setup the vsync and the length. For the scrollController we have the option of setting up the initialScrollOffset which defines where controller will start at.

Scrolling and Scrolling and Scrolling with Nested Scroll Views

The ScrollController used in this application was mainly used to control the NestedScrollView Widget. This widget allows us to safely embed a scrolling widget into another scrolling widget and have the two widgets interact with one another. In our case, the NestedScrollView is used to collapse the SliverAppBar which sits at the top of our application's viewport.

scroll.gif

On the second page of our application, we have an infinite ListView.builder widget. The SliverAppBar will only scroll down or up when the ListView.builder widget is at the top of its offset. When we use the ScrollController to programmatically change the offset of the SliverAppBar, the ListView.builder also is forced to scroll all the way to the top.

Tabbing and Scrolling With Buttons

Both our TabController and ScrollController expose a various array of methods which can be called to adjust their behavior and set their internal state. These methods are especially useful for when we want to specifically make the state of these widgets consistent or for when we want very specific behavior to occur. We can tab from one page to the next or scroll a widget to any offset that is in its range.

fab-control.png

In the FloatingActionButton on this application, we call the animatedTo and jumpTo methods to specifically move our scroll and tab views to various states. The animateTo method will animate the view with a specified curve and duration. We are able to define a duration between the Scroll and Tab animation's maximum and minimum animations speeds. With the ScrollController we can bypass these speeds by using the jumpTo method which will move the scrolling view to the offset instantaneously and without an animation.

The source code for this project can be found here

Video Tutorial

Projects and Series

Stand Alone Projects:
Building a Calculator
Movie Searcher Application

Minesweeper Game

Weather Application

Curriculum

Proof of Work Done

https://github.com/tensor-programming

H2
H3
H4
3 columns
2 columns
1 column
4 Comments