| // 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 MyApp()); |
| |
| class MyApp extends StatelessWidget { |
| const MyApp({super.key}); |
| |
| static const String _title = 'Flutter Code Sample'; |
| |
| @override |
| Widget build(BuildContext context) { |
| return MaterialApp( |
| title: _title, |
| home: Scaffold( |
| appBar: AppBar(title: const Text(_title)), |
| body: const MyStatelessWidget(), |
| ), |
| ); |
| } |
| } |
| |
| class _ArticleDescription extends StatelessWidget { |
| const _ArticleDescription({ |
| required this.title, |
| required this.subtitle, |
| required this.author, |
| required this.publishDate, |
| required this.readDuration, |
| }); |
| |
| final String title; |
| final String subtitle; |
| final String author; |
| final String publishDate; |
| final String readDuration; |
| |
| @override |
| Widget build(BuildContext context) { |
| return Column( |
| crossAxisAlignment: CrossAxisAlignment.start, |
| children: <Widget>[ |
| Expanded( |
| child: Column( |
| crossAxisAlignment: CrossAxisAlignment.start, |
| children: <Widget>[ |
| Text( |
| title, |
| maxLines: 2, |
| overflow: TextOverflow.ellipsis, |
| style: const TextStyle( |
| fontWeight: FontWeight.bold, |
| ), |
| ), |
| const Padding(padding: EdgeInsets.only(bottom: 2.0)), |
| Text( |
| subtitle, |
| maxLines: 2, |
| overflow: TextOverflow.ellipsis, |
| style: const TextStyle( |
| fontSize: 12.0, |
| color: Colors.black54, |
| ), |
| ), |
| ], |
| ), |
| ), |
| Expanded( |
| child: Column( |
| crossAxisAlignment: CrossAxisAlignment.start, |
| mainAxisAlignment: MainAxisAlignment.end, |
| children: <Widget>[ |
| Text( |
| author, |
| style: const TextStyle( |
| fontSize: 12.0, |
| color: Colors.black87, |
| ), |
| ), |
| Text( |
| '$publishDate - $readDuration', |
| style: const TextStyle( |
| fontSize: 12.0, |
| color: Colors.black54, |
| ), |
| ), |
| ], |
| ), |
| ), |
| ], |
| ); |
| } |
| } |
| |
| class CustomListItemTwo extends StatelessWidget { |
| const CustomListItemTwo({ |
| super.key, |
| required this.thumbnail, |
| required this.title, |
| required this.subtitle, |
| required this.author, |
| required this.publishDate, |
| required this.readDuration, |
| }); |
| |
| final Widget thumbnail; |
| final String title; |
| final String subtitle; |
| final String author; |
| final String publishDate; |
| final String readDuration; |
| |
| @override |
| Widget build(BuildContext context) { |
| return Padding( |
| padding: const EdgeInsets.symmetric(vertical: 10.0), |
| child: SizedBox( |
| height: 100, |
| child: Row( |
| crossAxisAlignment: CrossAxisAlignment.start, |
| children: <Widget>[ |
| AspectRatio( |
| aspectRatio: 1.0, |
| child: thumbnail, |
| ), |
| Expanded( |
| child: Padding( |
| padding: const EdgeInsets.fromLTRB(20.0, 0.0, 2.0, 0.0), |
| child: _ArticleDescription( |
| title: title, |
| subtitle: subtitle, |
| author: author, |
| publishDate: publishDate, |
| readDuration: readDuration, |
| ), |
| ), |
| ), |
| ], |
| ), |
| ), |
| ); |
| } |
| } |
| |
| class MyStatelessWidget extends StatelessWidget { |
| const MyStatelessWidget({super.key}); |
| |
| @override |
| Widget build(BuildContext context) { |
| return ListView( |
| padding: const EdgeInsets.all(10.0), |
| children: <Widget>[ |
| CustomListItemTwo( |
| thumbnail: Container( |
| decoration: const BoxDecoration(color: Colors.pink), |
| ), |
| title: 'Flutter 1.0 Launch', |
| subtitle: 'Flutter continues to improve and expand its horizons. ' |
| 'This text should max out at two lines and clip', |
| author: 'Dash', |
| publishDate: 'Dec 28', |
| readDuration: '5 mins', |
| ), |
| CustomListItemTwo( |
| thumbnail: Container( |
| decoration: const BoxDecoration(color: Colors.blue), |
| ), |
| title: 'Flutter 1.2 Release - Continual updates to the framework', |
| subtitle: 'Flutter once again improves and makes updates.', |
| author: 'Flutter', |
| publishDate: 'Feb 26', |
| readDuration: '12 mins', |
| ), |
| ], |
| ); |
| } |
| } |