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); } ); } }
I am using Bloc Pattern for retrieving data from Rest API (just called the whole object from JSON and parsed user name only). The Page consists of two tabs MyInformation and SmallCalendar. When the app runs the data are fetched correctly and everything is good. When I go to tab two and return to tab one then the whole screens in tab one goes to red showing error: Bad state: Stream has already been listened to.
StreamController<T> class Null safety. A controller with the stream it controls. This controller allows sending data, error and done events on its stream. This class can be used to create a simple stream that others can listen on, and to push events to that stream.
A subscription on events from a Stream. When you listen on a Stream using Stream. listen, a StreamSubscription object is returned. The subscription provides events to the listener, and holds the callbacks used to handle the events.
RxDart is an implementation of the popular reactiveX api for asynchronous programming, leveraging the native Dart Streams api.
You should use the following.
StreamController<...> _controller = StreamController<...>.broadcast();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With