因此,我使用流来跟踪用户的身份验证状态。这是我的设置,到目前为止效果很好。
class Root extends ConsumerWidget {
final Widget _loadingView = Container(color: Colors.white, alignment: Alignment.center, child: UiHelper.circularProgress);
@override
Widget build(BuildContext context, ScopedReader watch) {
return watch(userStreamProvider).when(
loading: () => _loadingView,
error: (error, stackTrace) => _loadingView,
data: (user) => user?.emailVerified == true ? Products() : Login(),
);
}
}
问题是,流多次构建 UI。我的产品页面中有一个欢迎对话框,它会打开多次,一旦我启动应用程序,它就会变得一团糟。
我应该怎么做才能避免这种情况?
** 这里我使用的是riverpod包