Flutter ListView | Flutter ListView builder

flutter researchthinker

Flutter Tutorial

Introduction

Flutter

Cross Platform

MVVM vs MVC vs MVP

Flutter Framework

Flutter Benefits

Flutter Comparison

Install Flutter in Win/Linux/Mac

Android Studio vs VsCode

Android Setup

VS Code Setup

VS Code Plugins

Android Studio Plugins

Flutter Widgets:

Flutter Basic Template

Flutter Commands

Top 10 Popular widgets

Flutter Stateless vs Stateful

Type of Widgets

Flutter Text widget

Flutter Text style

Textfield vs TextFormField

Flutter Scaffold

Flutter Container & SizedBox

Flutter Row & Column

Flutter Buttons

Flutter Stack

Flutter Forms

Flutter AlertDialog

Flutter Icons

Flutter Images

Flutter Drawer

Flutter ListView

Flutter GridView

Flutter Toast

Flutter Checkbox

Flutter Radio Button

Flutter Progress Bar

Flutter Tooltip

Flutter Slider

Flutter Table

Flutter SnackBar

Shimmer in Flutter

Bottom Navigation Bar in Flutter

Gesture Detector in Flutter

Error Handling in Flutter

DropDown in Flutter

Flutter Toggle

Auto Close Keyboard in Flutter

Screen size handling in Flutter

Flutter REST API

Flutter http

Flutter dio

dio vs http

Flutter Advance

Custom widget in Flutter

Flutter Navigator

Read Json in Flutter

Generate Excel in Flutter

Multiple Widgets in Flutter

Bottom sheet in Flutter

Copy to Clipboard in Flutter

Tab bar in Flutter

Code Editor in Flutter

Youtube Player in Flutter

Flutter App Development Tips

Flutter App version Update

Flutter Copy Text in App

Flutter Handle Null Value

Flutter Splash Screen

Flutter Disposable

Notification Listener

Flutter Switch Cases

Flutter Slivers

Flutter Custom App bar

Databinding in Flutter

Flutter Cards

Wrap vs Builder vs OverBarFlow

Flutter App Upgrade

GoogleMap vs FlutterMap

Circular progress contain Icon

DropDown Timer in Flutter

Flutter State management Comparison

Flutter vs Other Framework

Flutter Mixin

Passing values in Dart Files

WorkManager in Flutter

Flutter Database

Flutter Store Data

Suitable DB for Flutter

Backend for Flutter

SharedPreferences in Flutter

Flutter Token Expired Handling

Flutter Provider

Flutter Provider Tutorial

Flutter GetX

Flutter GetX tutorial

Flutter with Native

Flutter FFI

Flutter Testing

Flutter Tips

Best Practices

Reduce Flutter Screens

Tips to make app smart

Optimize App

Handle Multiple Pages

Interview Questions

Flutter 100 Interview Questions

Provider Interview Questions

GetX Interview Questions

BLoC Interview Questions

Flutter ListView

Flutter ListView

In Flutter, a ListView is a scrollable list of widgets. You can create a ListView to display a scrolling list of items. Whereas, ListView.builder is a more efficient way to create a list of items in Flutter, especially when dealing with a large number of items. It only creates widgets for the items that are currently visible on the screen, leading to improved performance.

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

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  final List<String> items = List.generate(100, (index) => 'Item $index');

  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Flutter ListView Example'),
        ),
        body: Column(
          children: [

//Case1
            Container(
              color:Colors.blue.shade100,
              height:300,
              width: MediaQuery.of(context).size.width,
              child: ListView(
              children: <Widget>[
                ListTile(
                  leading: Icon(Icons.star),
                  title: Text('Item 1'),
                  trailing: Text("Trailing 1"),
                  subtitle: Text('Subtitle for Item 1'),
                  onTap: () {
                    // Handle item tap
                  },
                ),
                ListTile(
                  leading: Icon(Icons.star),
                  title: Text('Item 2'),
                  trailing: Text("Trailing 2"),
                  subtitle: Text('Subtitle for Item 2'),
                  onTap: () {
                    // Handle item tap
                  },
                ),
                ListTile(
                  leading: Icon(Icons.star),
                  title: Text('Item 3'),
                  trailing: Text("Trailing 3"),
                  subtitle: Text('Subtitle for Item 3'),
                  onTap: () {
                    // Handle item tap
                  },
                ),
                // Add more ListTiles as needed
              ],
      ),
            ),

//case 2
            Container(
              color:Colors.green.shade100,
              height: 300,
              width:MediaQuery.of(context).size.width,
              child:  ListView.builder(
                  itemCount: items.length,
                  itemBuilder: (context, index) {
                    return ListTile(
                      title: Text(items[index]),
                      onTap: () {
                        // Handle item tap
                      },
                    );
                  },
                )
            )
          ],
        ),
    );
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

web_horizontal
About Us ♢ Disclaimer ♢ Privacy Policy ♢ Terms & Conditions ♢ Contact Us

Copyright © 2023 ResearchThinker.com. All rights reserved.