Flutter Custom ListTile Widget Example



A list tile displays a list of clickable items with a customizable background image. The user can swipe vertically to navigate through the list. Each item is either clickable or tappable and represents a single object from your data.

Flutter ListTile

here’s an example of how to use Flutter’s ListTile widget:

ListTile :

import 'package:flutter/material.dart';

class MyListTile extends StatelessWidget {
  const MyListTile({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ListTile(
      leading: CircleAvatar(
        child: Icon(Icons.person),
      ),
      title: Text('John Doe'),
      subtitle: Text('[email protected]'),
      trailing: IconButton(
        icon: Icon(Icons.arrow_forward),
        onPressed: () {},
      ),
    );
  }
}

In this example, we create a ListTile widget that displays information about a person. The ListTile widget is composed of several sub-widgets:

  • leading: A CircleAvatar widget with an Icon widget inside. This displays an avatar image or icon at the beginning of the list tile.
  • title: A Text a widget that displays the person’s name.
  • subtitle: A Text a widget that displays the person’s email address.
  • trailing: An IconButton widget with an arrow icon. This is typically used for a navigation action.

You can customize the appearance of each sub-widget as needed, such as changing the icon or background color of the CircleAvatar or IconButton. You can also add additional sub widgets to display more information, such as a person’s phone number or address.

Flutter listview listtile

To use the MyListTile widget in your app, you can simply add it to a ListView or another list-based widget, like this:

ListView(
  children: [
    MyListTile(),
    MyListTile(),
    MyListTile(),
  ],
)

This will display three instances of the MyListTile widget, each with different information about a person. You can customize each ListTile instance as needed to display the information you want.

Flutter listtile ripple effect

First, let’s create a basic ListTile widget:

ListTile(
  leading: Icon(Icons.account_circle),
  title: Text('John Doe'),
  subtitle: Text('[email protected]'),
  trailing: Icon(Icons.arrow_forward),
);

Now, let’s add a ripple effect to the ListTile when it’s tapped:

InkWell(
  onTap: () {},
  child: ListTile(
    leading: Icon(Icons.account_circle),
    title: Text('John Doe'),
    subtitle: Text('[email protected]'),
    trailing: Icon(Icons.arrow_forward),
  ),
);

The InkWell widget is used to add the ripple effect. We’ve wrapped the ListTile with the InkWell widget and added an empty onTap function that will be called when the ListTile is tapped.

However, this will only create a ripple effect on the InkWell itself, not on the entire ListTile. To fix this, we can wrap the ListTile with a Container and set its decoration to a Material with a ripple effect:

InkWell(
  onTap: () {},
  child: Container(
    decoration: BoxDecoration(
      border: Border(bottom: BorderSide(color: Colors.grey.shade300)),
      color: Colors.white,
    ),
    child: Material(
      color: Colors.transparent,
      child: ListTile(
        leading: Icon(Icons.account_circle),
        title: Text('John Doe'),
        subtitle: Text('[email protected]'),
        trailing: Icon(Icons.arrow_forward),
      ),
    ),
  ),
);

I

n this code, we’ve added a Container around the ListTile with a Border to separate each ListTile. We’ve also set the color of the Container to Colors.white to match the background color of the ListTile. Inside the Container, we’ve wrapped the ListTile with a Material widget with a color of Colors.transparent to make sure the background color doesn’t interfere with the ripple effect. Finally, we’ve set the Material widget’s child property to the original ListTile.

Now, when you tap on the ListTile, a ripple effect will appear over the entire ListTile. You can customize the ripple effect further by setting properties on the Material widget, such as splashColor and highlightColor.

Flutter ListTile Widget Example

Flutter List tile

Read also, the Flutter Notification badge example.

  • Boost WooCommerce Security: Set Up OTP Login in WordPress
    Passwords, while essential for security, can be vulnerable to hacking and breaches. To add an extra layer of protection for your WooCommerce store, consider implementing an OTP (One-Time Password) login. This guide walks you through the process of setting up an OTP login in WordPress for enhanced security. Why Use OTP Login? Enhanced Security: OTPs …

    Read more …

  • How to Create Woocommerce Flutter App for WordPress free
    Absolutely! Let’s break down how to create a WooCommerce Flutter app for your WordPress store. Here’s a comprehensive outline of the process and essential considerations: 1. Setup Your Development Environment 2. Project Structure 3. Dependencies 4. Core Functionality 5. User Interface (UI) and User Experience 6. Additional Features (Optional) Example Code Snippet (Fetching Products) Important …

    Read more …

  • How to Add a Link to Your Facebook Story in 2024
    Facebook Stories have become an integral part of our social media experience, allowing us to share moments and updates with our friends and followers. But did you know that you can also add links to your Facebook Stories? Adding a link to your story can be a powerful way to drive traffic to your website, …

    Read more …

  • Troubleshooting “Failed to download Laravel from dist” Error
    If you encounter the “Failed to download Laravel from dist” error while working with Laravel 10, it is likely due to the absence of the zip extension and unzip/7z commands on your system. This error prevents the successful download of Laravel from the distribution (dist) repository. What causes this error? The error occurs when the …

    Read more …

  • Solutions for “The file is too large for the destination file system” Error on Pendrive
    If you have ever encountered the frustrating error message “The file is too large for the destination file system” when trying to transfer files to your pendrive, don’t worry! There are a few solutions you can try to resolve this issue. 1. Format the Pendrive: One of the easiest ways to fix this error is …

    Read more …

Leave a Comment