我需要从SQLite数据库的2列中检索值,并且我正在使用帮助程序查询。
我尝试索引值。
print("In the login List : "+ lg[0].toString());
但我得到了
In the login List : {email: [email protected], password: xxxx}
Future<bool> loginUser(String username, String password) async {
bool isSuccess;
Database db = await this.database;
List<Map<String, dynamic>> lg = await db.query(regTable,
columns: [colEmail, colPassword],
where: "$colEmail = ? AND $colPassword = ?",
whereArgs: [username, password]);
if (lg.length > 0) {
print("In the login List : "+ lg[0].toString());
isSuccess = true;
} else {
isSuccess = false;
}
return isSuccess;
}
我需要能够单独检索电子邮件和密码。就像,print(Email : lg(email));
我想我已经明白了。
lg.forEach((f){
print(f["password"]);
});
这让我得到了我想要的东西。但如果你有一些建议请随意。
你有List
的Map
s。看起来您想要从该列表生成特定键值的列表。 List
方法map
非常适合这类问题。例如:
final emails = lg.map((item) => item["email"]),
passwords = lg.map((item) => item["password"]);
(这些实际上是普通的Iterable
s;如果你想要List
s,最后只需添加.toList()
。)