【发布时间】:2020-01-05 13:11:21
【问题描述】:
显然我在这里做错了什么......登录后,我将新的布尔值(T)发送到 isAuthorized 流。 StreamBuilder 重新运行并最终执行正确的 if-else 分支,但由于某种原因,Login Widget 仍然呈现在屏幕上?
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'App',
theme: appTheme,
initialRoute: '/',
home: StreamBuilder<bool>(
stream: getIt.get<SessionBloc>().isAuthorized,
initialData: false,
builder: (context, snapshot) {
if (snapshot.data) {
return Home();
} else {
return Login();
}
},
),
routes: {
'/': (context) => Home(),
'/profile': (context) => Profile(),
'/login': (context) => Login(),
'/register': (context) => Register(),
},
),
);
}
}
【问题讨论】: