Continuo recebendo mensagem de exceção referente ao campo contacts.id ser UNIQUE, mesmo retirando da função save o contactMap['id'] = contact.id;
Performing hot restart...
Syncing files to device sdk gphone x86 arm...
Restarted application in 1.890ms.
E/flutter (14097): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: DatabaseException(UNIQUE constraint failed: contacts.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY)) sql 'INSERT INTO contacts (id, name, account_number) VALUES (?, ?, ?)' args [0, alex, 1000]}
E/flutter (14097): #0 wrapDatabaseException (package:sqflite/src/exception_impl.dart:11:7)
E/flutter (14097): <asynchronous suspension>
E/flutter (14097): #1 SqfliteDatabaseMixin.txnRawInsert.<anonymous closure> (package:sqflite_common/src/database_mixin.dart:394:14)
E/flutter (14097): <asynchronous suspension>
E/flutter (14097): #2 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33:16)
E/flutter (14097): <asynchronous suspension>
E/flutter (14097): #3 SqfliteDatabaseMixin.txnSynchronized (package:sqflite_common/src/database_mixin.dart:346:14)
E/flutter (14097): <asynchronous suspension>
E/flutter (14097): #4 main.<anonymous closure> (package:bank/main.dart)
E/flutter (14097): <asynchronous suspension>
E/flutter (14097):
Funão save do meu app_database:
Future<int> save(Contact contact) {
return createDatabase().then((db) {
final Map<String, dynamic> contactMap = Map();
contactMap['name'] = contact.name;
contactMap['account_number'] = contact.accountNumber;
return db.insert('contacts', contactMap);
});
}
Meu runApp no main.dart:
void main() {
runApp(BankApp());
save(Contact(0, 'alex', 1000)).then((id) {
findAll().then((contacts) => debugPrint(contacts.toString()));
});
}
Minhas versões:
[√] Flutter (Channel stable, 2.0.3, on Microsoft Windows [versão 10.0.19041.867], locale pt-BR)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] IntelliJ IDEA Community Edition (version 2021.1)
[√] VS Code (version 1.48.2)
[√] Connected device (3 available)