Home > Net >  Flutter type 'Future<dynamic>' is not a subtype of type 'bool' error
Flutter type 'Future<dynamic>' is not a subtype of type 'bool' error

Time:10-31

I want to browse through the documents with for on Firestore and query whether there is a value equal to the e-mail address I entered with the controller structure. For this I followed a code like below. But it gives me the error mentioned in the title. What can I do about it?

My Code:

masterEmailGet() {
  var _usersDoc = await FirebaseFirestore.instance.collection('Master').get();
  for (var eleman in _usersDoc.docs) {
    if (eleman.data()['masterEmail'] == _emailController.text) {
      return true;
    }
  }
}

Error:

type 'Future<dynamic>' is not a subtype of type 'bool'
 

Called:

InkWell(
   onTap: () { 
      if (masterEmailGet()) {
         _auth.signIn(_emailController.text, _passController.text).then((value) {
         return Navigator.push(context, MaterialPageRoute(builder: ((context) => BottomNavBar())));
        });
       }
   },

I've done a lot of research on the internet but haven't found a working solution.

CodePudding user response:

Since masterEmailGet returns a Future, you need to await for its call in if. Also add async in the function body masterEmailGet() async { /* */ }.

onTap: () async { 
    if (await masterEmailGet()) {
        // ...
    }
}
  • Related