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
: ACircleAvatar
widget with anIcon
widget inside. This displays an avatar image or icon at the beginning of the list tile.title
: AText
a widget that displays the person’s name.subtitle
: AText
a widget that displays the person’s email address.trailing
: AnIconButton
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
Read also, the Flutter Notification badge example.
- How to Conduct YouTube Keyword Research Easily?Introduction YouTube is the second largest search engine in the world, making it a valuable platform for content creators and businesses alike. To maximize your visibility and reach on YouTube, it is crucial to conduct proper keyword research. By identifying the right keywords, you can optimize your videos for search and increase your chances of …
- How to upgrade the Dart SDK version in flutterIf you’re a Flutter developer, you know how important it is to stay up-to-date with the latest version of the Dart SDK. Upgrading the Dart SDK ensures that you have access to the latest features, bug fixes, and performance improvements. Step 1: Check Your Current Dart SDK Version Before you begin the upgrade process, it’s …
- Why Do Advertisers Use Testimonials?In the ever-competitive business landscape, nurturing strong connections with your customers remains paramount for enhancing your credibility and positioning yourself as an industry authority. Establishing credibility is the bedrock upon which trust is built, ultimately translating into increased sales. To bolster your company’s credibility, integrating testimonial advertising into your marketing strategy is essential. So, what …
- How To Earn $5 Fast Method!Looking to boost your income by $25 in less than an hour? This isn’t the start of a clichéd sales pitch; it’s about discovering several quick and simple ways to earn $5 online within minutes. For instance, you can make five bucks by completing tasks such as taking brief surveys, participating in short website usability …
- What Does BMF Mean On TikTok? Latest Social Media AcronymsIn the fast-paced world of social media, acronyms are the language of choice, enabling users to communicate swiftly without the need for lengthy phrases. While classics like LOL and OMG are still in use, the younger generation on TikTok has introduced a new acronym into the mix: BMF. So, what exactly does BMF mean, and …