List Tiles
Part of the Lists and Screens section of Coddy's Flutter journey. Lesson 2 of 33.
Most rows in a list look alike: a main line, sometimes a smaller line under it, maybe an icon at each end. ListTile is that row, ready made, with the right sizes and padding.
ListTile(
title: Text('Ada Lovelace'),
subtitle: Text('+1 555 0101'),
)The title is the main line. The subtitle goes under it, smaller and in a softer color. Both take a widget, usually a Text.
A ListTile is as wide as its list and grows to fit two lines when it has a subtitle. Put several in a ListView and you have a contact list.
Challenge
EasyAda's row is already a ListTile. Turn the other two texts into tiles like hers:
Alan Turingwith the subtitle+1 555 0102Grace Hopperwith the subtitle+1 555 0103
Try it yourself
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('Contacts')),
body: ListView(
children: const [
ListTile(
title: Text('Ada Lovelace'),
subtitle: Text('+1 555 0101'),
),
Text('Alan Turing'),
Text('Grace Hopper'),
],
),
),
);
}
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Lists and Screens
1Scrolling Lists
A List That ScrollsList TilesLeading and TrailingTap a List TileDividers Between Rows6Tabs, Drawers and Swipes
Tabs With a Navigation BarFilled Icons for the Open TabA Side DrawerSwipe to DeleteUndo a SwipePractice on your own: Online Flutter compiler