Flutter - ListView
De Aulas
Afluentes: Dispositivos Móveis; Usabilidade, desenvolvimento web, mobile e jogos
ListView Estática
1import 'package:flutter/material.dart';
2
3void main() {
4 runApp(
5 MaterialApp(
6 title: 'Flutter ListView',
7 theme: ThemeData(
8 primarySwatch: Colors.deepOrange,
9 ),
10 home: Scaffold(
11 appBar: AppBar(
12 title: Text("ListView Simples"),
13 ),
14 body: Center(
15 child: ListView(
16 children: [
17 ListTile(
18 leading: Icon(Icons.map),
19 title: Text('Mapa'),
20 ),
21 ListTile(
22 leading: Icon(Icons.photo_album),
23 title: Text('Álbum'),
24 ),
25 ListTile(
26 leading: Icon(Icons.phone),
27 title: Text('Fone'),
28 ),
29 ],
30 ),
31 ),
32 ),
33 ),
34 );
35}
Lista de Array
1import 'package:flutter/material.dart';
2
3void main() => runApp(App());
4
5class App extends StatefulWidget {
6 @override
7 _AppState createState() => _AppState();
8}
9
10class _AppState extends State<App> {
11 var cities = [
12 'Florianópolis',
13 'São José',
14 'Palhoça',
15 'Biguaçu',
16 'Itajaí',
17 'Blumenau'
18 ];
19
20 @override
21 build(context) {
22 return MaterialApp(
23 title: 'Lista',
24 home: ListView.builder(
25 itemCount: cities.length,
26 itemBuilder: (context, index) {
27 return Text(cities[index]);
28 },
29 ),
30 );
31 }
32}