如何从地图列表中逐列检索数据?

问题描述 投票:0回答:2

我需要从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));

database list sqlite dart flutter
2个回答
0
投票

我想我已经明白了。

      lg.forEach((f){
        print(f["password"]);
      });

这让我得到了我想要的东西。但如果你有一些建议请随意。


0
投票

你有ListMaps。看起来您想要从该列表生成特定键值的列表。 List方法map非常适合这类问题。例如:

final emails = lg.map((item) => item["email"]), 
  passwords = lg.map((item) => item["password"]);

(这些实际上是普通的Iterables;如果你想要Lists,最后只需添加.toList()。)

© www.soinside.com 2019 - 2024. All rights reserved.