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

Function returns null

var result;
  
void searching() async{

  var searchData = await FirebaseFirestore.instance.collection('users').where('email',isEqualTo: userEmail).get();
  
    setState(() {
      result = searchData.docs.first;
    });
  }

  
void addFollowing(var username , var email , var phoneNumber) async{
  searching();
  await FirebaseFirestore.instance.collection('users').doc(result).collection('following').doc().set({
    'username':username,
    'email':email,
    'phoneNumber':phoneNumber
  });
  print(result);
}

I have two function searching and addfollowing . The searching function returns a document that matches the given email and sets the id of that document in result . But it returns null for some reason when i call that fucntion in the addfollowing function .

I am using the add following function on an onTap of a gesturedetector. The first press returns null but the second press returns the data .

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 :

the searching is not complete then yet. you need to await it. So change

searching();

to

await searching();

Also, I believe you need to change this

void searching() async{

to this as well

Future searching() async{
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