Виджет ListTile в Flutter
Готовая строка Material-списка с фиксированными
зонами -
ListTile.
Не нужно вручную выравнивать текст
и иконки в Row:
виджет сам раскладывает содержимое по
шаблону.
Главная подпись задаётся параметром
title, обычно это
Text.
Вторичная строка мельче и светлее,
её задаёт subtitle. Слева
leading часто занимает
Icon
или аватар. Справа trailing -
стрелка, переключатель или короткая метка.
Любой слот можно опустить, хватит
одного title для пункта меню:
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(home: HomePage()));
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: const [
ListTile(
leading: Icon(Icons.folder),
title: Text('Documents'),
subtitle: Text('12 files'),
trailing: Icon(Icons.chevron_right),
),
ListTile(
leading: Icon(Icons.photo),
title: Text('Photos'),
subtitle: Text('Album "Vacation"'),
trailing: Text('248'),
),
],
),
);
}
}
Добавьте три ListTile:
ListView(
children: [
ListTile(
leading: Icon(Icons.menu_book),
title: Text('Algebra'),
subtitle: Text('Equations'),
),
ListTile(
leading: Icon(Icons.public),
title: Text('History'),
subtitle: Text('Ancient world'),
),
ListTile(
leading: Icon(Icons.science),
title: Text('Physics'),
subtitle: Text('Mechanics'),
trailing: Icon(Icons.star),
),
],
)