我目前能夠成功地將值插入系統,但是,我希望能夠在我的控制臺中顯示插入的值。如何在控制臺中列印插入的值?我嘗試這樣做,但我只能獲得插入值的“id”。我不確定如何列印表中的其余值。
這是我的插入代碼:
// Insert Operation: Insert a Note object to database
Future<int> insertNote(Note note) async {
//getting db reference
Database db = await database;
//running the insert command
//our data from note is converted to map object
var result = await db.insert(noteTable, note.toMap());
if (kDebugMode) {
print('Note data inserted successfully: $result');
}
return result;
}
這是我用來將 Note 物件轉換為 Map 物件的代碼
// Convert a Note object into a Map object
Map<String, dynamic> toMap() {
var map = <String,dynamic>{};
if (id != null) {
map['id'] = _id;
}
map['title'] = _title;
map['description'] = _description;
map['priority'] = _priority;
map['color'] = _color;
map['date'] = _date;
return map;
}
這是我控制臺上的結果:

uj5u.com熱心網友回復:
當您在資料庫中插入行時,您只會得到行 ID 作為回報。
因此,如果您想列印最近的資料,那么您必須使用 id 查詢您的資料庫,或者您也可以列印所有可用資料。
餐桌用
db.query("table_name);
或者
db.rawQuery('SELECT * FROM "table"');
對于特定的 id
db.query("table_name",where: '$rowId = ?', whereArgs: [id]);
或者
db.rawQuery('SELECT * FROM "table" WHERE $rowId = $id');
有關更多資訊,請查看:https : //pub.dev/packages/sqflite
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/398935.html
