list_tile.2.dart 1.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flutter code sample for [ListTile].

import 'package:flutter/material.dart';

void main() => runApp(const ListTileApp());

class ListTileApp extends StatelessWidget {
  const ListTileApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
17
      theme: ThemeData(useMaterial3: true),
18 19 20 21 22 23 24 25 26 27 28 29
      home: const ListTileExample(),
    );
  }
}

class ListTileExample extends StatelessWidget {
  const ListTileExample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('ListTile Sample')),
30
      body: ListView(
31 32 33 34 35 36 37 38 39
        children: const <Widget>[
          ListTile(
            leading: CircleAvatar(
              child: Text('A')
            ),
            title: Text('Headline'),
            subtitle: Text('Supporting text'),
            trailing: Icon(Icons.favorite_rounded),
          ),
40
          Divider(height: 0),
41 42 43 44 45 46 47 48
          ListTile(
            leading: CircleAvatar(
              child: Text('B')
            ),
            title: Text('Headline'),
            subtitle: Text('Longer supporting text to demonstrate how the text wraps and how the leading and trailing widgets are centered vertically with the text.'),
            trailing: Icon(Icons.favorite_rounded),
          ),
49
          Divider(height: 0),
50 51 52 53 54 55 56 57 58
          ListTile(
            leading: CircleAvatar(
              child: Text('C')
            ),
            title: Text('Headline'),
            subtitle: Text("Longer supporting text to demonstrate how the text wraps and how setting 'ListTile.isThreeLine = true' aligns leading and trailing widgets to the top vertically with the text."),
            trailing: Icon(Icons.favorite_rounded),
            isThreeLine: true,
          ),
59
          Divider(height: 0),
60 61 62 63 64
        ],
      ),
    );
  }
}