-1

I had a factory method for converting json into an object which accepted Map<String, dynamic> json as argument from sqlite database like below

 factory Lecturer.fromJson(Map<String, dynamic> json)=>Lecturer(
    name:json['name'],
    email: json['email'],
  );

the data is returned in a future builder and access like this

          FutureBuilder(
              future: DB.getLecturer(),
              builder: (_,lect){
                if(!lect.hasData){
                  return CircularProgressIndicator();
                }
               Lecturer l=Lecturer.fromJson(lect.data[0]);
              }),

but after upgrading my flutter to a newer version I realized the return type for SQL queries is no longer Map<String, dynamic> but rather Map<String, Object?> , I now get the error below from a code that was working perfectly just last week. Please any help will be appreciated

Error: The operator '[]' isn't defined for the class 'Object?'

1 Answers1

0

in you builder specify the lect type as AsyncSnapshot:

      builder: (_, AsyncSnapshot lect){
        if(!lect.hasData){
          return CircularProgressIndicator();
        }               
           Lecturer l=Lecturer.fromJson(lect.data[0]);
          }
Benyamin
  • 1,008
  • 11
  • 18