Olá, estou acompanhando o exercício da aula porém o método findAll() não está retornando nada no debugPrint quando vou testar. Alguém consegue me dar uma ajuda?
Arquivo database:
import 'package:bytebank/model/contact.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
Future<Database> createDatabase(){
return getDatabasesPath().then((dbPath) {
final String path = join(dbPath, 'bytebank.db');
return openDatabase(path, onCreate: (db, version){
db.execute('CREATE TABLE contacts('
'id INTEGER PRIMARY KEY, '
'name TEXT, '
'account_number INTEGER)');
}, version: 1);
});
}
Future<int> save(Contact contact) {
return createDatabase().then((db) {
final Map<String, dynamic> contactMap = Map();
contactMap['id'] = contact.id;
contactMap['name'] = contact.nome;
contactMap['account_number'] = contact.numero;
return db.insert('contacts', contactMap);
});
}
Future<List<Contact>> findAll() {
return createDatabase().then((db) {
return db.query('contacts').then((maps) {
final List<Contact> contacts = [];
for (Map<String, dynamic> map in maps) {
final Contact contact = Contact(
map['id'],
map['name'],
map['account_number'],
);
contacts.add(contact);
}
return contacts;
});
});
}
Arquivo main:
import 'package:bytebank/model/contact.dart';
import 'package:bytebank/screens/contact_form.dart';
import 'package:bytebank/screens/dashboard.dart';
import 'package:flutter/material.dart';
import 'database/app_database.dart';
void main() {
runApp(BytebankApp());
save(Contact(0, 'alex', 1000)).then((id) {
findAll().then((contacts) => print(contacts.toString()));
});