【发布时间】:2021-07-23 22:12:55
【问题描述】:
第一次打开应用程序时,直到我点击屏幕或开始滚动,图像和流值才会呈现。在流构建器中返回小部件之前,请确保 snapshot.data 打印出正确的值。
Row(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset(
'assets/profile_image.png',
height: 36.0,
width: 36.0,
),
SizedBox(width: 10.0),
StreamBuilder<String>(
stream: context.read<UserBloc>().balanceStream,
builder: (context, snapshot) {
print('ConnectionState is ${snapshot.connectionState}');
switch (snapshot.connectionState) {
case ConnectionState.active:
print('Value is ${snapshot.data}');
return NonScalingTextView(
"\$ ${snapshot.data}",
style: TitleTiny,
);
break;
default:
return Container();
}
},
),
],
);
在首次启动后执行一些用户交互或热重新加载或热重启应用程序,小部件按预期呈现。
【问题讨论】: