Quando tento executar o codigo recebo a seguinte mensagem no run:
"E/SQLiteLog(12057): (1) no such table: contacts in "INSERT INTO contacts (name, account_number) VALUES (?, ?)" D/EGL_emulation(12057): app_time_stats: avg=8536.01ms min=8536.01ms max=8536.01ms count=1 E/flutter (12057): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: DatabaseException(no such table: contacts (code 1 SQLITE_ERROR): , while compiling: INSERT INTO contacts (name, account_number) VALUES (?, ?)) sql 'INSERT INTO contacts (name, account_number) VALUES (?, ?)' args [Guilherme, 58122]"
import 'package:bytebank/models/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.name;
contactMap['account_number'] = contact.accountNumber;
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;
});
});
}