Facebook Twitter Instagram
    DeepCrazyWorld
    Facebook Twitter Instagram Pinterest YouTube
    • FLUTTER
      • FLUTTER APP
        • QRCode
        • Quiz App
        • Chat GPT
        • PDF App
        • News App
        • Fitness App
        • Weather App
        • BMI Calculator
        • GAME APP
        • Ecommerce App
        • wallpaper App
        • Finance app
        • Chat App
        • Wallet App
        • Taxi App
        • Quran app
        • Music player app
      • FLUTTER UI
        • Splash Screen
        • Onboarding Screen
        • Login Screen
        • Card Design
        • Drawer
    • PROJECT
      • Android Projects
      • College Projects
      • FLUTTER APP
      • Project Ideas
      • PHP Projects
      • Python Projects
    • SOURCE CODE
    • ANDROID
      • ANDROID APP
      • GAME APP
      • ANDROID STUDIO
    • MCQ
      • AKTU MCQ
        • RPA MCQ
        • COA MCQ
        • HPC MCQ
        • SPM MCQ
        • Renewable Energy All MCQ
        • Data Compression MCQ
        • Data Structure MCQ
        • Digital Image Processing MCQ
        • Software Engineering MCQ
        • Machine Learning MCQ
        • Artificial Intelligence MCQ
      • D PHARMA MCQ
        • Pharmaceutics – I MCQ
        • Pharmacognosy MCQ
        • Pharmaceutical Chemistry MCQ
        • Biochemistry and Clinical Pathology MCQ
        • Human Anatomy and Physiology MCQ
        • Heath Education and Community Pharmacy MCQ
    • INTERVIEW QUESTIONS
      • Flutter Interview Questions
      • INTERVIEW QUESTIONS
      • Python Interview Questions
      • Coding ninjas solution
    • MORE
      • WORDPRESS
        • SEO
        • TOP 10 WORDPRESS THEME
      • PRODUCTIVITY
      • Program
      • QUOTES
    DeepCrazyWorld
    Home»FLUTTER UI»How to make ListView Builder Ui in flutter with Source Code
    FLUTTER UI

    How to make ListView Builder Ui in flutter with Source Code

    DeepikaBy DeepikaAugust 29, 2024Updated:March 15, 2025No Comments5 Mins Read

    To create a beautiful ListView in Flutter that displays a list of books, ListView ui in Flutter – where each row contains an image (loaded using CachedNetworkImage), a title, and a formatted date and time, follow these steps. The CachedNetworkImage package will be used to handle loading and caching images efficiently.

    Table of Contents

    Toggle
    • Step-by-Step Guide to Creating a ListView Builder with Cached Network Images
      • Step 1: Set Up Your Flutter Project
      • Step 2: Add Dependencies
      • Step 3: Implement the ListView in main.dart
    • Output
    • Explanation of the Code
    • Step-by-Step Guide to Run the App
    • What to Expect
    • Customization Tips
    • Related Articles

    Step-by-Step Guide to Creating a ListView Builder with Cached Network Images

    Step 1: Set Up Your Flutter Project

    First, make sure you have Flutter installed, and create a new Flutter project:

    flutter create listview_example
    cd listview_example

    Step 2: Add Dependencies

    Add the cached_network_image dependency to your pubspec.yaml file to handle image loading and caching:

    dependencies:
      flutter:
        sdk: flutter
      cached_network_image: ^3.2.3 # Ensure to check for the latest version

    Run flutter pub get to install the new dependency.

    Step 3: Implement the ListView in main.dart

    Now, let’s modify the lib/main.dart file to implement a ListView.builder with images, titles, and formatted date and time.

    import 'package:flutter/material.dart';
    import 'package:cached_network_image/cached_network_image.dart';
    import 'package:intl/intl.dart'; // For date formatting
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,  // Remove debug banner
          title: 'ListView Example',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: ListViewExample(),
        );
      }
    }
    
    class ListViewExample extends StatelessWidget {
      final List<Book> books = List.generate(
        10,
        (index) => Book(
          title: 'Book Title ${index + 1}',
          imageUrl: 'https://via.placeholder.com/150', // Placeholder image URL
          dateTime: DateTime.now().subtract(Duration(days: index)), // Dynamic date
        ),
      );
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Books List'),
          ),
          body: ListView.builder(
            scrollDirection: Axis.horizontal,  // Set the scroll direction to horizontal
            itemCount: books.length,
            itemBuilder: (context, index) {
              return Container(
                width: 200,  // Set a fixed width for each item
                child: BookListItem(book: books[index]),
              );
            },
          ),
        );
      }
    }
    
    class BookListItem extends StatelessWidget {
      final Book book;
    
      BookListItem({required this.book});
    
      @override
      Widget build(BuildContext context) {
        return Card(
          margin: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
          elevation: 4,
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
          child: ListTile(
            leading: ClipRRect(
              borderRadius: BorderRadius.circular(8.0),
              child: CachedNetworkImage(
                imageUrl: book.imageUrl,
                placeholder: (context, url) => CircularProgressIndicator(),
                errorWidget: (context, url, error) => Icon(Icons.error),
                width: 50,
                height: 50,
                fit: BoxFit.cover,
              ),
            ),
            title: Text(
              book.title,
              style: TextStyle(fontWeight: FontWeight.bold),
            ),
            subtitle: Text(
              DateFormat('yyyy-MM-dd – kk:mm').format(book.dateTime), // Format date and time
              style: TextStyle(color: Colors.grey[600]),
            ),
          ),
        );
      }
    }
    
    class Book {
      final String title;
      final String imageUrl;
      final DateTime dateTime;
    
      Book({required this.title, required this.imageUrl, required this.dateTime});
    }
    

    Output

    Remove background color from here

     body: Container(
            // decoration: BoxDecoration(
            //   gradient: LinearGradient(
            //     colors: [
            //       Colors.blue[200]!,
            //       Colors.blue[600]!
            //     ], // Gradient background
            //     begin: Alignment.topLeft,
            //     end: Alignment.bottomRight,
            //   ),
            // ),

    Explanation of the Code

    1. Dependencies:
    • We use cached_network_image to load and cache images efficiently.
    • intl is used for formatting the date and time.
    1. Data Model (Book Class):
    • The Book class represents a book with a title, an image URL, and a DateTime object.
    1. Sample Data:
    • A list of Book objects is generated dynamically with different dates and titles.
    1. ListView Implementation:
    • The ListView.builder widget creates a scrollable list of BookListItem widgets. Each BookListItem represents a row in the list. ListView ui in Flutter with source code.
    1. Custom ListTile (BookListItem):
    • Card Widget: Used to give each row a card-like appearance with rounded corners and elevation.
    • ListTile Widget: Displays the book image (leading), title (title), and formatted date and time (subtitle).
    • CachedNetworkImage Widget: Displays the book cover image. It shows a loading indicator while the image is loading and an error icon if the image fails to load.
    1. Date Formatting:
    • The date and time are formatted using DateFormat('yyyy-MM-dd – kk:mm') to create a readable string. ListView ui in Flutter

    Step-by-Step Guide to Run the App

    1. Save the Code: Ensure you save your changes to main.dart.
    2. Run the App: Use the following command to run the app on a connected device or emulator:
       flutter run

    What to Expect

    When you run the app, you will see a list of books displayed using a ListView. Each row shows:

    • An image (loaded and cached from the network).
    • The book title in bold.
    • The date and time formatted nicely in grey text.

    The rows have a card-like appearance with rounded corners and a shadow effect to enhance the UI.

    Customization Tips

    • Change the Image URL: Replace the placeholder URL with actual URLs to display real book covers.
    • Customize the Date Format: Modify the DateFormat string to change how dates and times are displayed.
    • Styling: You can further customize the TextStyle for titles and subtitles to match your design needs.

    Related Articles

    • How to make Ludo app in Flutter with Source Code Step by step
    • How to make PDF Reader app in Flutter with Source Code Step by step
    • How to make QR Scanner app in Flutter with Source Code Step by step
    • How to Make a ToDo App with Flutter with source Code StepWise in 2024
    • What is package in Flutter (Dart) with example in 2024
    • What is class in Flutter(Dart) with example step by step
    • Advantage of Flutter with examples in 2024
    • Top 15 Amazing Applications Built with Flutter Framework
    • Specialized PDF reader designed specifically for music sheets
    • Christmas Quote Generator app built with flutter source code
    • How to make review and rating ui with flutter stepwise
    • Create custom social login button Google, Facebook and Apple ui

    Share. Facebook Twitter LinkedIn WhatsApp Telegram Pinterest Reddit Email
    Previous ArticleCreate a TabBar View in flutter with fully functional stepwise
    Next Article How to Create Music Player UI screen with fully functional in flutter

    Related Posts

    Implementing a Dynamic FAQ Screen UI in Flutter Using ExpansionTile

    FLUTTER 5 Mins Read

    Creating an Instruction UI Screen in Flutter Application

    FLUTTER UI 7 Mins Read

    Animated Backgrounds in Flutter: A Complete Guide

    FLUTTER 4 Mins Read

    How to Create Music Player UI screen with fully functional in flutter

    FLUTTER APP 3 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • Implementing a Dynamic FAQ Screen UI in Flutter Using ExpansionTile March 29, 2025
    • Creating an Instruction UI Screen in Flutter Application March 29, 2025
    • Animated Backgrounds in Flutter: A Complete Guide March 15, 2025
    • How to make Diary App using flutter stepwise using getx August 31, 2024
    • How to Create Music Player UI screen with fully functional in flutter August 30, 2024
    • How to make ListView Builder Ui in flutter with Source Code August 29, 2024
    • Create a TabBar View in flutter with fully functional stepwise August 28, 2024
    • How to create TabBar view in flutter with source code step wise August 27, 2024
    • How to make Heart rate measure app with Flutter stepwise August 26, 2024
    • How to make ChatGpt App in flutter with source code Stepwise August 25, 2024
    Facebook Twitter Instagram Pinterest YouTube
    • About
    • Contact
    • Disclaimer
    • Privacy Policy
    Copyright by DeepCrazyWorld © 2025

    Type above and press Enter to search. Press Esc to cancel.