Flutter returning a bool type from a Future Method

前端 未结 1 754
遇见更好的自我
遇见更好的自我 2021-01-20 12:53

This question is quite similar to this but the explanation didn\'t quite help for my use-case. I have a method of type Future that return a bool performing a query to cloud

1条回答
  •  后悔当初
    2021-01-20 13:27

    The return type returned from doesNameAlreadyExist is Future, so the line doesNameAlreadyExist("userName", usernameController.value) == true, is actually Future == bool. You need to await, or then the result.

    doesNameAlreadyExist("userName", usernameController.value).then(value => value == true)
    

    or

    (await doesNameAlreadyExist("userName", usernameController.value)) == true
    

    Read more about async programming here: Dart Futures

    0 讨论(0)
提交回复
热议问题