Is there a way to load async data on InitState method?

前端 未结 9 1553
你的背包
你的背包 2020-12-05 16:39

I\'m a looking for a way to load async data on InitState method, I need some data before build method runs. I\'m using a GoogleAuth code, and I need to execute build method

9条回答
  •  臣服心动
    2020-12-05 17:36

    @override
      void initState() {
        super.initState();
         _userStorage.getCurrentUser().then((user) {
          setState(() {
            if (user.isAuthenticated) {
              Timer.run(() {
                redirectTo();
              });
            }
          });
        });
      }
    
     void redirectTo() {
        Navigator.push(context,
            MaterialPageRoute(builder: (BuildContext context) => new ShopOrders()));
      }
    

提交回复
热议问题