How To Create Long Dynamic Listview Items In Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 12-10-2020

In Flutter Dart ListView.builder() widget is used to make both simple and dynamic List. The ListView.builder() widget comes with a super functionality that it can load only the items which is showing on the mobile screen and dose not load all the items together. This would make the ListView more fast and memory efficient. Because using this it will not take more memory and app will run on Low RAM. The ListView.builder() widget has a return area which is loaded every time only when user scrolls the screen and load only items which is displaying on device screen area.

How To Create Long Dynamic Listview Items In Flutter Android App

Long Dynamic Listview Items
Complete Code For Long Dynamic Listview Items In Flutter
Main.dart

import 'package:flutter/material.dart';
import 'dart:math';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  List<String> getListViewItems() {
    var items = List<String>.generate(10000, (count) => " Item $count ");
    return items ;
  }

  @override
  Widget customListView(){
    var listItems = getListViewItems() ;
    var listView = ListView.builder(
        itemBuilder: (context, index){
          return ListTile(
            title: Text(listItems[index]),
            leading: Icon(Icons.chevron_right),
            onTap: (){
              print('ListView Item = '+'$index' + ' Clicked ');
              },
          );
        }
    );
    return listView ;
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: Scaffold(
            appBar: AppBar(
              backgroundColor: Colors.indigo,
              title: Text("Long Dynamic ListView"),
            ),
            body: SafeArea(child: customListView())
        )
    );
  }
}

Related Post