Search code examples
flutterdartdynamicgoogle-cloud-firestorenavigator

'_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Venue'


This is my problem. In a screen, I'm using a Navigator.pushnamed()... with arguments to send info to a screen with a detailed view. It works fine! This is the code:

Navigator.pushNamed(context, VenueDetailScreen.id, arguments: snapshot.data[index]);

In a SearchDelegate, I'm trying to do the same in buildSuggestions, but I'm having an error. This are the code and the error:

results.map<Widget>(
                (a) => Container(
                  margin: EdgeInsets.symmetric(vertical: 10.0),
                  child: GestureDetector(
                    onTap: () {
                      print(a.data);
                      Navigator.pushNamed(context, VenueDetailScreen.id, arguments: a.data);
                    },
                    child: ListTile(
                      title: Text(
                        a.data['nombre'].toString(),
                      ),

The error: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Venue'

I'll appreciate your help to understand what isn't working. Thanks!


Solution

  • a.data is a map you need to cast it to the model by doing something like Venue.fromJson(a.data)

    results.map<Widget>(
                    (a) => Container(
                      margin: EdgeInsets.symmetric(vertical: 10.0),
                      child: GestureDetector(
                        onTap: () {
                          print(a.data);
                          Navigator.pushNamed(context, VenueDetailScreen.id, arguments: Venue.fromJson(a.data));
                        },
                        child: ListTile(
                          title: Text(
                            a.data['nombre'].toString(),
                          ),