Boa noite, após a abstração dos códigos, ao clicar na lista de contatos, o app gera o erro: type 'Null' is not a subtype of type 'List<dynamic>' in type cast
Segue meu arquivo contact_dao.dart
class ContactDao {
static const String _tableName = 'contacts';
static const String _id = 'id';
static const String _name = 'name';
static const String _accountNumber = 'account_number';
static const String tableSql = 'CREATE TABLE contacts('
'id INTEGER PRIMARY KEY, '
'name TEXT, '
'accountNumber INTEGER)';
Future<int> save(Contact contact) async {
final Database db = await getDatabase();
Map<String, dynamic> contactMap = _toMap(contact);
return db.insert(_tableName, contactMap);
}
Future<List<Contact>> findAll() async {
final Database db = await getDatabase();
final List<Map<String, dynamic>> result = await db.query(_tableName);
List<Contact> contacts = _toList(result);
return contacts;
}
List<Contact> _toList(List<Map<String, dynamic>> result) {
final List<Contact> contacts = [];
for (Map<String, dynamic> row in result) {
final Contact contact = Contact(
row[_id],
row[_name],
row[_accountNumber],
);
contacts.add(contact);
}
return contacts;
}
Map<String, dynamic> _toMap(Contact contact) {
final Map<String, dynamic> contactMap = {};
contactMap[_name] = contact.name;
contactMap[_accountNumber] = contact.accountNumber;
return contactMap;
}
}
Segue o build do contact_list.dart
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Contacts'),
backgroundColor: Theme.of(context).primaryColor,
),
body: FutureBuilder(
initialData: const [],
future: _dao.findAll(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: const <Widget>[
CircularProgressIndicator(color: Colors.green),
SizedBox(
height: 20,
),
Text(
'Loading',
style: TextStyle(fontSize: 25),
),
],
),
);
case ConnectionState.active:
// TODO: Handle this case.
break;
case ConnectionState.done:
final contacts = (snapshot.data as List);
return ListView.builder(
itemCount: contacts.length,
itemBuilder: (context, index) {
final contact = contacts[index];
return _ContactItem(contact);
},
);
}
return const Text('Unknown error');
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const ContactForm())).then((value) => setState(() {}));
},
child: const Icon(Icons.add),
),
);
}
Antes das abstrações estava funcionando mas tentei voltar e mesmo assim não consegui. Alguma luz amiga...???