Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The argument type 'Object?' can't be assigned to the parameter type 'String?

I get this error with my function, "The argument type ‘Object?’ can’t be assigned to the parameter type ‘String?’." on the lines containing snapshot.docs[0].data(”),

Please help me fix it, any help would be greatly appreciated!

Future getNewsPostDetails(String newsPostId) async {

    QuerySnapshot snapshot = await FirebaseFirestore.instance.collection('newsPosts').where('newsPostId', isEqualTo: newsPostId).get();
      newsPostDetails blogPostDetails = newsPostDetails(
      newsPostTitle: snapshot.docs[0].data('newsPostTitle'),
      newsPostAuthor: snapshot.docs[0].data('newsPostAuthor'),
      newsPostContent: snapshot.docs[0].data('newsPostContent') ,
      date: snapshot.docs[0].data('date'),
    );
    return blogPostDetails;
  }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you make sure that snapshot.docs[0].data('newsPostTitle') is a String, you can convert it to String like:

snapshot.docs[0].data('newsPostTitle') as String?
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading