Building Dynamic Lists in Flutter with ListViews

nader dabit
Instructornader dabit

Share this video with your friends

Send Tweet
Published 4 years ago
Updated 2 years ago

ListView is the most commonly used scrolling widget in a Flutter application. In this video, we'll learn how to create dynamic lists using Flutter's ListView widget to render both lists of Strings & lists of Maps

Instructor: [00:01] We'll begin with the basic material app with the home set to main app. Main app returns a scaffold containing an app bar and a body. In the body of this scaffold, we'd like to render a list of text widgets. We'll first define a variable of people and set it to a list.

[00:34] Next, we'll update the child of the center widget to be a listview.builder. Listview.builder builds the children of the list on demand. The builder constructor is appropriate for list views with a large, unknown, or infinite number of children because the builder is called only for those children that are actually visible.

[00:54] We'll first set the item count to the length of our list. The item builder method will be used to build the items within our list. The item builder method will be called the number of times set as the item count. In the item builder, we'll return a text widget set to the value of the index of the current item in the people array.

[01:34] Next, we'll look at how to render a list of maps. First, we'll update the items in our list to be of type map. Next, in the item builder function, we'll return the people index with the name property. We can also add padding to the list by setting a padding property.