Estou com esse problema mesmo depois de aplicar a solução para gerar um mock, utilizando o @GenerateMocks, eu li essa solução em uma das duvidas aqui do curso, e tentei implementar, porém continuo tendo o mesmo problema, já consultei o repositório para ver se tinha feito algo errado, mas está tudo de acordo com oque foi passado, como eu posso resolver?
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following _TypeError was thrown running a test:
type 'Null' is not a subtype of type 'Future<List<Contact>>'
When the exception was thrown, this was the stack:
#0 MockContactDao.findAll (package:bytebank/database/dao/contact_dao.dart:26:25)
#1 main.<anonymous closure> (file:///D:/Projetos/AluraFlutter/bytebank/test/contact_list_flow_test.dart:17:25)
#2 main.<anonymous closure> (file:///D:/Projetos/AluraFlutter/bytebank/test/contact_list_flow_test.dart:15:40)
#3 testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:170:29)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)
The test description was:
Should save a contact
linha 26:25 no qual o erro se refere :
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;
}
Classe de contact_list:
import 'package:bytebank/database/dao/contact_dao.dart';
import 'package:bytebank/models/contacts.dart';
import 'package:bytebank/screens/contact_form.dart';
import 'package:bytebank/screens/transaction_form.dart';
import 'package:bytebank/widget/progress.dart';
import 'package:flutter/material.dart';
class ContactsList extends StatefulWidget {
final ContactDao contactDao;
const ContactsList({Key? key, required this.contactDao}) : super(key: key);
@override
State<ContactsList> createState() => _ContactsListState();
}
class _ContactsListState extends State<ContactsList> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).primaryColor,
title: const Text('Transfers'),
),
body: FutureBuilder<List<Contact>>(
initialData: const [],
future: widget.contactDao.findAll(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
break;
case ConnectionState.waiting:
return const Progress();
case ConnectionState.active:
break;
case ConnectionState.done:
final List<Contact> contacts = snapshot.data!;
return ListView.builder(
itemBuilder: (context, index) {
Contact contact = contacts[index];
return _ContactItem(
contact: contact,
onClick: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => TransactionForm(contact)));
},
);
},
itemCount: contacts.length,
);
}
return const Text('Unknown error');
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (context) => ContactForm(
contactDao: widget.contactDao,
)))
.then((value) {
setState(() {});
});
},
child: const Icon(Icons.add),
),
);
}
}