Dividers Between Rows
Part of the Lists and Screens section of Coddy's Flutter journey. Lesson 5 of 33.
Rows that sit right against each other are hard to tell apart. A Divider draws a thin grey line across the list:
ListView(
children: [
ListTile(title: Text('Wi-Fi')),
Divider(),
ListTile(title: Text('Bluetooth')),
],
)It goes between two rows, so a list of four rows needs three dividers, and none after the last row.
Divider takes a few settings when you want it different: thickness: for the line, color:, and indent: to start it further from the left edge.
Challenge
EasyThe settings list has a line between Wi-Fi and Bluetooth only. Add a Divider between every two rows, so there are three lines and none after Sound.
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('Settings')),
body: ListView(
children: const [
ListTile(leading: Icon(Icons.wifi), title: Text('Wi-Fi')),
Divider(),
ListTile(leading: Icon(Icons.bluetooth), title: Text('Bluetooth')),
ListTile(leading: Icon(Icons.battery_full), title: Text('Battery')),
ListTile(leading: Icon(Icons.volume_up), title: Text('Sound')),
],
),
),
);
}
}
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