text
stringlengths 1
474
|
|---|
interactivity tutorial.
|
<topic_end>
|
<topic_start>Lists & grids
|
<topic_end>
|
<topic_start>
|
Topics
|
<topic_end>
|
<topic_start>Use lists
|
Displaying lists of data is a fundamental pattern for mobile apps.
|
Flutter includes the ListView
|
widget to make working with lists a breeze.<topic_end>
|
<topic_start>
|
Create a ListView
|
Using the standard ListView constructor is
|
perfect for lists that contain only a few items.
|
The built-in ListTile
|
widget is a way to give items a visual structure.
|
<code_start>ListView(
|
children: const <Widget>[
|
ListTile(
|
leading: Icon(Icons.map),
|
title: Text('Map'),
|
),
|
ListTile(
|
leading: Icon(Icons.photo_album),
|
title: Text('Album'),
|
),
|
ListTile(
|
leading: Icon(Icons.phone),
|
title: Text('Phone'),
|
),
|
],
|
),<code_end>
|
<topic_end>
|
<topic_start>
|
Interactive example
|
<code_start>import 'package:flutter/material.dart';
|
void main() => runApp(const MyApp());
|
class MyApp extends StatelessWidget {
|
const MyApp({super.key});
|
@override
|
Widget build(BuildContext context) {
|
const title = 'Basic List';
|
return MaterialApp(
|
title: title,
|
home: Scaffold(
|
appBar: AppBar(
|
title: const Text(title),
|
),
|
body: ListView(
|
children: const <Widget>[
|
ListTile(
|
leading: Icon(Icons.map),
|
title: Text('Map'),
|
),
|
ListTile(
|
leading: Icon(Icons.photo_album),
|
title: Text('Album'),
|
),
|
ListTile(
|
leading: Icon(Icons.phone),
|
title: Text('Phone'),
|
),
|
],
|
),
|
),
|
);
|
}
|
}<code_end>
|
<topic_end>
|
<topic_start>Create a horizontal list
|
You might want to create a list that scrolls
|
horizontally rather than vertically.
|
The ListView widget supports horizontal lists.Use the standard ListView constructor, passing in a horizontal
|
scrollDirection, which overrides the default vertical direction.
|
<code_start>ListView(
|
// This next line does the trick.
|
scrollDirection: Axis.horizontal,
|
children: <Widget>[
|
Container(
|
width: 160,
|
color: Colors.red,
|
),
|
Container(
|
width: 160,
|
color: Colors.blue,
|
),
|
Container(
|
width: 160,
|
color: Colors.green,
|
),
|
Container(
|
width: 160,
|
color: Colors.yellow,
|
),
|
Container(
|
width: 160,
|
color: Colors.orange,
|
),
|
],
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.