Segui o passo a passo a risca do video, mas quando tento executar o codigo tenho o seguinte erro:
E/flutter (23417): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value E/flutter (23417): #0 MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:142:86) E/flutter (23417): #1 MethodChannel.invokeMethod (package:flutter/src/services/platformchannel.dart:148:36) E/flutter (23417): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:331:12) E/flutter (23417): #3 invokeMethod (package:sqflite/src/sqflite_impl.dart:17:13) E/flutter (23417): #4 SqfliteDatabaseFactoryImpl.invokeMethod (package:sqflite/src/factory_impl.dart:82:7) E/flutter (23417): #5 SqfliteDatabaseFactoryMixin.safeInvokeMethod. (package:sqflite_common/src/factory_mixin.dart:41:38) E/flutter (23417): #6 wrapDatabaseException (package:sqflite/src/exception_impl.dart:7:32) E/flutter (23417): #7 SqfliteDatabaseFactoryImpl.wrapDatabaseException (package:sqflite/src/factory_impl.dart:78:7) E/flutter (23417): #8 SqfliteDatabaseFactoryMixin.safeInvokeMethod (package:sqflite_common/src/factory_mixin.dart:41:7) E/flutter (23417): #9 SqfliteDatabaseFactoryMixin.getDatabasesPath (package:sqflite_common/src/factory_mixin.dart:153:26) E/flutter (23417): #10 getDatabasesPath (package:sqflite/sqflite.dart:161:54) E/flutter (23417): #11 createDataBase (package:bytebank/database/app_database.dart:6:10) E/flutter (23417): #12 save (package:bytebank/database/app_database.dart:18:10) E/flutter (23417): #13 main (package:bytebank/main.dart:8:3) E/flutter (23417): #14 runMainZoned.. (dart:ui/hooks.dart:142:25) E/flutter (23417): #15 _rootRun (dart:async/zone.dart:1354:13) E/flutter (23417): #16 _CustomZone.run (dart:async/zone.dart:1258:19) E/flutter (23417): #17 _runZoned (dart:async/zone.dart:1789:10) E/flutter (23417): #18 runZonedGuarded (dart:async/zone.dart:1777:12) E/flutter (23417): #19 _runMainZoned. (dart:ui/hooks.dart:138:5) E/flutter (23417): #20 _delayEntrypointInvocation. (dart:isolate-patch/isolatepatch.dart:283:19) E/flutter (23417): #21 RawReceivePortImpl.handleMessage (dart:isolate-patch/isolate_patch.dart:184:12) E/flutter (23417):
Codigo do DataBase:
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.account;
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['name'],
map['account_number'],
map['id']);
contacts.add(contact);
}
return contacts;
});
});
}
Chamada dele no Main:
void main() {
save(Contact('William', 13456, 452)).then((id) {
findAll().then((contacts) => print(contacts));
});
runApp(ByteBankApp());
}