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: const Text("ListView Simples"),
13 ),
14 body: Center(
15 child: ListView(
16 children: const [
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(const App());
4
5class App extends StatefulWidget {
6 const App({super.key});
7
8 @override
9 State<App> createState() => _AppState();
10}
11
12class _AppState extends State<App> {
13 var cities = [
14 'Florianópolis',
15 'São José',
16 'Palhoça',
17 'Biguaçu',
18 'Itajaí',
19 'Blumenau'
20 ];
21
22 @override
23 build(context) {
24 return MaterialApp(
25 title: 'Lista',
26 home: Scaffold(
27 appBar: AppBar(title: const Text("Cidades")),
28 body: ListView.builder(
29 itemCount: cities.length,
30 itemBuilder: (BuildContext context, int index) {
31 return ListTile(
32 leading: const Icon(Icons.location_city),
33 title: Text(cities[index]),
34 );
35 },
36 ),
37 ),
38 );
39 }
40}