Boolean expression must not be null?

前端 未结 4 1098
慢半拍i
慢半拍i 2021-01-23 20:46

Does anyone know why i got the Failed assertion: boolean expression must not be null. If I had logged in and quit the app and open the app again i should be directly in the home

4条回答
  •  孤城傲影
    2021-01-23 21:01

    Your problem is that you are not waiting for your Future to resolve to an actual value.

    This line:

    userIsLoggedIn = value;
    

    might not have been reached when your build method is called. Because it's async and you don't await it.

    You can set a default value to userIsLoggedIn, maybe false, that will solve your immediate problem. But it will not solve your real problem, that your program logic is asynchronous.

    You will probably want to build your app with at least one FutureBuilder.

    See: What is a Future and how do I use it?

提交回复
热议问题