dart - 颤振:坏状态:流已经被收听
问题描述
class MyPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: new Scaffold(
appBar: TabBar(
tabs: [
Tab(child: Text("MY INFORMATION",style: TextStyle(color: Colors.black54),)),
Tab(child: Text("WEB CALENDER",style: TextStyle(color: Colors.black54),)),
],
),
body:PersonalInformationBlocProvider(
movieBloc: PersonalInformationBloc(),
child: TabBarView(
children: [
MyInformation(),
new SmallCalendarExample(),
],
),
),
),
);
}
}
class MyInformation extends StatelessWidget{
// TODO: implement build
var deviceSize;
//Column1
Widget profileColumn(PersonalInformation snapshot) => Container(
height: deviceSize.height * 0.24,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius:
new BorderRadius.all(new Radius.circular(50.0)),
border: new Border.all(
color: Colors.black,
width: 4.0,
),
),
child: CircleAvatar(
backgroundImage: NetworkImage(
"http://www.binaythapa.com.np/img/me.jpg"),
foregroundColor: Colors.white,
backgroundColor: Colors.white,
radius: 40.0,
),
),
ProfileTile(
title: snapshot.firstName,
subtitle: "Developer",
),
SizedBox(
height: 10.0,
),
],
)
],
),
);
Widget bodyData(PersonalInformation snapshot) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
profileColumn(snapshot)
],
),
);
}
@override
Widget build(BuildContext context) {
final personalInformationBloc = PersonalInformationBlocProvider.of(context);
deviceSize = MediaQuery.of(context).size;
return StreamBuilder(
stream: personalInformationBloc.results,
builder: (context,snapshot){
if (!snapshot.hasData)
return Center(
child: CircularProgressIndicator(),
);
return bodyData(snapshot.data);
}
);
}
}
我正在使用 Bloc 模式从 Rest API 检索数据(仅从 JSON 调用整个对象并仅解析用户名)。该页面由两个选项卡 MyInformation 和 SmallCalendar 组成。当应用程序运行时,数据被正确获取并且一切都很好。当我转到标签二并返回标签一时,标签一中的整个屏幕变为红色,显示错误:
Bad state: Stream has already been listened to.
解决方案
您应该使用以下内容。
StreamController<...> _controller = StreamController<...>.broadcast();
推荐阅读
- wpf - 使用 Binding on header 将 Header Style 添加到 DataGrid 覆盖(隐藏)数据
- python - 如何优化 tkinter 按钮创建以更快地完成?
- laravel - Laravel、惯性和 vuejs
- python - 如何通过字典为DataFrame中的每一行设置基于其他列的唯一列ID
- c - GCC 如果调度
- mysql - 将旧表中的数据移动到具有相同列名的新表中
- angular - 如何在 Angular Jasmine 中为以下场景编写单元测试用例?
- react-native - 如何解决无法编译 react-native-app、expo?
- javascript - 在 JQuery 中导出 jqgrid 的 Pdf 和 Excel 文件
- excel - 为什么选择了中间过滤掉的行但没有被删除?