Flutter中的守卫

Flutter中的守卫,第1张

Flutter中的守卫

我也在这个问题上绊脚石,最终

FutureBuilder
为此使用了一个。看看我的路线:

final routes = {  '/': (BuildContext context) => FutureBuilder<AuthState>(    // This is my async call to sharedPrefs    future: AuthProvider.of(context).authState$.skipWhile((_) => _ == null).first,    builder: (BuildContext context, AsyncSnapshot<AuthState> snapshot) {      switch(snapshot.connectionState) {        case ConnectionState.done:          // When the future is done I show either the LoginScreen// or the requested Screen depending on AuthState          return snapshot.data == AuthState.SIGNED_IN ? JobsScreen() : LoginScreen()        default:          // I return an empty Container as long as the Future is not resolved          return Container();      }    },  ),};

如果要跨多个路径重用代码,则可以扩展FutureBuilder。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5016675.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存