Flutter - ListView

De Aulas

Afluentes: Dispositivos Móveis; Usabilidade, desenvolvimento web, mobile e jogos

ListView Estática

import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      title: 'Flutter ListView',
      theme: ThemeData(
        primarySwatch: Colors.deepOrange,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text("ListView Simples"),
        ),
        body: Center(
          child: ListView(
            children: const [
              ListTile(
                leading: Icon(Icons.map),
                title: Text('Mapa'),
              ),
              ListTile(
                leading: Icon(Icons.photo_album),
                title: Text('Álbum'),
              ),
              ListTile(
                leading: Icon(Icons.phone),
                title: Text('Fone'),
              ),
            ],
          ),
        ),
      ),
    ),
  );
}

Lista de Array

import 'package:flutter/material.dart';

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

class App extends StatefulWidget {
  const App({super.key});

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  var cities = [
    'Florianópolis',
    'São José',
    'Palhoça',
    'Biguaçu',
    'Itajaí',
    'Blumenau'
  ];

  @override
  build(context) {
    return MaterialApp(
      title: 'Lista',
      home: Scaffold(
        appBar: AppBar(title: const Text("Cidades")),
        body: ListView.builder(
          itemCount: cities.length,
          itemBuilder: (BuildContext context, int index) {
            return ListTile(
              leading: const Icon(Icons.location_city),
              title: Text(cities[index]),
            );
          },
        ),
      ),
    );
  }
}