Key ListView Flutter

Flutter ListView.builder[] example

Last updated on October 14, 2021 A Goodman Loading... Loading... Post a comment

Flutter

[ 325 Articles]

Flutter: GridView.builder[] Example

October 14, 2021

How to read data from local JSON files in Flutter

October 27, 2021

Flutter: Vertically center a widget inside a Container

March 25, 2021

Flutter & SQLite: CRUD Example [2022]

January 3, 2022

How to set width, height, and padding of TextField in Flutter

January 13, 2022

Using GetX [Get] for Navigation and Routing in Flutter

October 27, 2021

How to create a Filter/Search ListView in Flutter [2022]

January 4, 2022

Customize Borders of TextField/TextFormField in Flutter

January 13, 2022

More

report this ad

ListView.builder[] is used to render long or infinite lists, especially lists of data fetched from APIs like products, news, messages, search results Only visible items of the lists are called to reduce resource [CPU, RAM] consumption and improve performance.

Example

1. Create a new Flutter project with the following:Advertisements

flutter create my_product_list

2. Remove all the default code in lib/main.dart and add the following:

import 'package:flutter/material.dart'; void main[] { runApp[const MyApp[]]; } class MyApp extends StatelessWidget { const MyApp[{Key? key}] : super[key: key]; @override Widget build[BuildContext context] { return MaterialApp[ // Hide the debug banner debugShowCheckedModeBanner: false, title: 'Kindacode.com', home: MyHomePage[], ]; } } class MyHomePage extends StatelessWidget { MyHomePage[{Key? key}] : super[key: key]; // Generate a dummy list final myProducts = List.generate[1000, [i] => 'Product $i']; @override Widget build[BuildContext context] { return Scaffold[ appBar: AppBar[ title: const Text['Product List'], ], body: Container[ // Use ListView.builder child: ListView.builder[ // the number of items in the list itemCount: myProducts.length, // display each item of the product list itemBuilder: [context, index] { return Card[ // In many cases, the key isn't mandatory key: UniqueKey[], child: Padding[ padding: const EdgeInsets.all[10], child: Text[myProducts[index]]], ]; }], ]]; } }

3. Run the project:

flutter run

The result:

Conclusion

AdvertisementsWeve examined a complete example of implementing a list view in Flutter with the ListView.builder constructor. If youd like to learn more new and interesting stuff about mobile development, take a look at the following articles:

  • How to create a Filter/Search ListView in Flutter
  • Working with ReorderableListView in Flutter
  • Sorting Lists in Dart and Flutter [5 Examples]
  • Flutter SliverList Tutorial and Example
  • Flutter AnimatedList Tutorial and Examples

You can also check out our Flutter topic page or Dart topic page for the latest tutorials and examples.

Advertisements
Share Tweet Telegram
Subscribe
Notify of
I allow to use my email address and send notification about new comments and replies [you can unsubscribe at any time].
Label
{} [+]
Name*
Email*
Label
{} [+]
Name*
Email*
0 Comments
Inline Feedbacks
View all comments

Related Articles

Flutter: Convert UTC Time to Local Time and Vice Versa

February 3, 2022

Using Chip widget in Flutter: Tutorial & Examples

January 24, 2022

Flutter: Changing App Display Name for Android & iOS

January 20, 2022

Flutter: SliverGrid example [2022]

January 18, 2022

Create a Custom NumPad [Number Keyboard] in Flutter

January 14, 2022

Flutter: GridPaper example

January 10, 2022

Best Libraries for Making HTTP Requests in Flutter [2022]

January 7, 2022

Dart: Convert Class Instances [Objects] to Maps and Vice Versa

January 7, 2022

Creating Masonry Layout in Flutter with Staggered Grid View

January 7, 2022

Flutter: Creating Custom Back Buttons

December 28, 2021

Flutter: Creating an Auto-Resize TextField

December 28, 2021

Flutter: Columns with Percentage Widths

December 28, 2021

Video liên quan

Chủ Đề