当我将值数据库添加到映射值 null 时,在颤动中添加原因

in flutter when I add value database to map value null is add why

Flutter 中的 SQLite 数据库

''' {

Future<List<Dataid>> getPerson() async {
       var dbC = await db;
       List<Map<String, dynamic>> maps =await dbC.rawQuery("SELECT * FROM $TABLE");
       List<Dataid> persons = [];
       if (maps.length > 0) {
         for (int i = 0; i < maps.length; i++) {       
             persons.add(Dataid.fromMap(maps[i]));      ///error is in this line 
              print(maps.length);
              print("${maps[i]}");
              print(persons);
             }  }
         return persons;  } 

''' 当我从数据库中获取数据并添加到地图时,它会添加空值?? 这里 ''' {

   class Dataid {
   String id;
   String name;
   String srname;
   Dataid(this.id, this.name, this.srname);

   Map<String, dynamic> toMap() {
    var map = <String, dynamic>{
      'id': id,
      'name': name,
      'srname': srname,
   };
   return map;
}

 Dataid.fromMap(
   Map<String, dynamic> map,
  ) {
    id = map['id'];
    name = map['name'];
    srname = map['srname'];
 }

 }

''' 我的错误是: ''' {

  print(maps.length);
              print("${maps[i]}");
              print(persons);
   //when i print this result is
    means problem
    I/flutter (31391): 30
    I/flutter (31391): {ID: 1, NAME: david, SRNAME: john}
    I/flutter (31391): [Dataid{id: null, name: null, age: null}]

''' 添加到地图 a

时出现问题

提前致谢

我不确定,因为我还没有将 SQLiteFlutter 一起使用,但问题可能在于 maps[i] 中的键是大写的,而您正在使用它们Dataid.fromMap().

中的小写形式

试试这个:

 Dataid.fromMap(
   Map<String, dynamic> map,
  ) {
    id = map['ID'];
    name = map['NAME'];
    srname = map['SRNAME'];
 }