Jian, posta seu código, fica mais facil de ajudar.
segue o código completo para contacts_list.dart
import 'package:bytebank_aula2/database/dao/contact_dao.dart';
import 'package:bytebank_aula2/models/contact.dart';
import 'package:bytebank_aula2/screens/contact_form.dart';
import 'package:flutter/material.dart';
class ContactsList extends StatefulWidget {
const ContactsList({Key? key}) : super(key: key);
@override
_ContactsListState createState() => _ContactsListState();
}
class _ContactsListState extends State<ContactsList> {
final ContactDao _dao = ContactDao();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Contacts"),
),
body: FutureBuilder<List<Contact>>(
initialData: const [],
future: _dao.findAll(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
// TODO: Handle this case.
break;
case ConnectionState.waiting:
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: const <Widget>[
CircularProgressIndicator(),
Text('Loading')
],
));
case ConnectionState.active:
// TODO: Handle this case.
break;
case ConnectionState.done:
final List<Contact>? contacts = snapshot.data;
return ListView.builder(
itemBuilder: (context, index) {
final Contact contact = contacts![index];
return _ContactItem(contact);
},
itemCount: contacts!.length,
);
}
return const Text('Unknown error');
},
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
await Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const ContactForm()));
// Force update (rebuild widget)
setState(() {});
},
child: const Icon(
Icons.add,),
)
);
}
}
class _ContactItem extends StatelessWidget {
final Contact contact;
const _ContactItem(this.contact);
@override
Widget build(BuildContext context) {
return Card(
child: ListTile(
title: Text(
contact.name,
style: const TextStyle(
fontSize: 24,
),
),
subtitle: Text(
contact.accountNumber.toString(),
style: const TextStyle(
fontSize: 16.0,
),
),
));
}
}