in flutter when I add value database to map value null is add why
397
I'm not sure as I haven't used SQLite
with Flutter
yet, but maybe the problem is that the keys in maps[i]
are uppercase and you are using their lowercase forms in Dataid.fromMap()
.
Try this:
Dataid.fromMap(
Map<String, dynamic> map,
) {
id = map['ID'];
name = map['NAME'];
srname = map['SRNAME'];
}
Author by
Admin
Updated on December 29, 2022Comments
-
Admin over 1 year
SQLite database in flutter
''' {
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; }
''' when I get data from database and add into map it add null value ?? here ''' {
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']; } }
''' my error is: ''' {
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}]
''' problem during add into map a
Thankyou in advance
-
Admin about 3 yearswhere i add this , it is already add in my Dataid class
-
Andrej about 3 yearsReplace your
Dataid.fromMap
with the code I gave you. -
Admin about 3 yearsThankyou , yaa my mistake is due to small letter in map['ID'] 😄 😂
-
Andrej about 3 yearsNo problem! :) Please consider clicking on the green checkmark to mark the answer as correct.