我是颤振应用程序开发的新手。在我的颤振应用程序中,我使用路径提供程序插件和 SQFLite 创建了一个数据库。但它不起作用,它显示异常消息类型“未来”不是“未来”类型的子类型
我在这里添加我的代码
static final DatabaseHelper _instance = new DatabaseHelper.internal();
factory DatabaseHelper() => _instance;
static Database _db;
Future<Database> get db async {
if (_db != null) {
return _db;
}
_db = await initDb();
return _db;
}
DatabaseHelper.internal();
initDb() async {
Directory documentDirectory = await getApplicationDocumentsDirectory();
String path = join(documentDirectory.path, "tododatabase.db");
var ourDb = await openDatabase(path, version: 1, onCreate: _onCreate);
return ourDb;
}
Future _onCreate(Database db, int version) async {
await db.execute(
"CREATE TABLE TodoList(id INTEGER PRIMARY KEY, todoText TEXT)");
// print("Table is created");
}
//insertion
Future<int> saveTodo(Todo todo) async {
var dbClient = await db;
int res = await dbClient.insert(" TodoList", todo.toMap());
return res;
}
请帮我。请给个建议。提前致谢。
0631/com.stunntech.fluttertodoapp E/flutter: [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
type '(Database, int) => void' is not a subtype of type '(Database, int) => Future<dynamic>'
#0 DatabaseHelper.initDb (package:flutter_todo_app/database/database.dart:29:64)
<asynchronous suspension>
#1 DatabaseHelper.db (package:flutter_todo_app/database/database.dart:20:17)
<asynchronous suspension>
#2 DatabaseHelper.saveTodo (package:flutter_todo_app/database/database.dart:40:26)
<asynchronous suspension>
#3 _MyTodoListState._submitTodo (package:flutter_todo_app/todo_list.dart:144:30)
<asynchronous suspension>
#4 _MyTodoListState._showAlert.<anonymous closure> (package:flutter_todo_app/todo_list.dart:97:19)
#5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
#6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
#7 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:94:7)
#8 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
#9 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
#10 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
#11 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
#12 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
#13 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
#14 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
#15 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
#16 _invoke1 (dart:ui/hooks.dart:134:13)
#17 _dispatchPointerDataPacket (dart:ui/hooks.dart:91:5)enter code here
这是我得到的日志。