Flutter, “Stream has already been listened to” error in GridView
What I'm doing is to fetch cartoon list and show by GridView. Below code is fetching data
Future<void> _getWebtoonData() async {
var response;
if(_daysReceivedResponse[_pressedButtonDayIndex]){
response = _daysResponse[_pressedButtonDayIndex];
} else {
response= await http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week='+_currentWebtoonAddress);
_daysReceivedResponse[_pressedButtonDayIndex] = true;
_daysResponse[_pressedButtonDayIndex] = response;
}
dom.Document document = parser.parse(response.body);
final e1 = document.querySelectorAll('.img_list .thumb');
final e2 = document.querySelectorAll('.img_list .desc');
final e3 = document.querySelectorAll('.img_list .rating_type');
List<List<String>> infoCollection = List<List<String>>();
List<String> info = List<String>();
for(int i=0; i<e1.length; i++){
info.add(e1[i].getElementsByTagName('img')[0].attributes['src']);
info.add(e1[i].getElementsByTagName('a')[0].attributes['title']);
info.add(e2[i].getElementsByTagName('a')[0].innerHtml);
info.add(e3[i].getElementsByTagName('strong')[0].innerHtml);
infoCollection.add(info);
}
_controller.sink.add(infoCollection);
}
And I'm showing this images, titles, artists and rate by GridView like below
Widget _getWebtoonGridView() {
return StreamBuilder(
stream: _controller.stream.asBroadcastStream(),
builder: (BuildContext context, AsyncSnapshot<List> snapshot){
if(snapshot.hasError)
print(snapshot.error);
else if(snapshot.hasData){
return GridView.count(
crossAxisCount: 3,
childAspectRatio: 0.6,
children: List.generate(snapshot.data.length, (index){
return _getWebtoonInfo(index, snapshot.data[index]);
}),
);
}
else if(snapshot.connectionState != ConnectionState.done)
return Center(child: CircularProgressIndicator());
},
);
}
But "Stream has already been listened to" error is occurring continuously, what is the problem about my StreamController??
How can I fix it?
StackTrace
I/flutter (21411): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════ I/flutter
(21411): The following StateError was thrown building Expanded(flex:
1): I/flutter (21411): Bad state: Stream has already been listened to.
I/flutter (21411): I/flutter (21411): When the exception was thrown,
this was the stack: I/flutter (21411): #4
_StreamBuilderBaseState._subscribe (package:flutter/src/widgets/async.dart:135:37) I/flutter (21411): #5
_StreamBuilderBaseState.initState (package:flutter/src/widgets/async.dart:109:5) I/flutter (21411): #6
StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:3830:58) I/flutter
(21411): #7 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3696:5) I/flutter (21411):
8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14) I/flutter
(21411): #9 Element.updateChild
(package:flutter/src/widgets/framework.dart:2753:12)
StreamController variable
StreamController<List<List<String>>> _controller = StreamController<List<List<String>>>.broadcast();
gridview controller

|
show 5 more comments
What I'm doing is to fetch cartoon list and show by GridView. Below code is fetching data
Future<void> _getWebtoonData() async {
var response;
if(_daysReceivedResponse[_pressedButtonDayIndex]){
response = _daysResponse[_pressedButtonDayIndex];
} else {
response= await http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week='+_currentWebtoonAddress);
_daysReceivedResponse[_pressedButtonDayIndex] = true;
_daysResponse[_pressedButtonDayIndex] = response;
}
dom.Document document = parser.parse(response.body);
final e1 = document.querySelectorAll('.img_list .thumb');
final e2 = document.querySelectorAll('.img_list .desc');
final e3 = document.querySelectorAll('.img_list .rating_type');
List<List<String>> infoCollection = List<List<String>>();
List<String> info = List<String>();
for(int i=0; i<e1.length; i++){
info.add(e1[i].getElementsByTagName('img')[0].attributes['src']);
info.add(e1[i].getElementsByTagName('a')[0].attributes['title']);
info.add(e2[i].getElementsByTagName('a')[0].innerHtml);
info.add(e3[i].getElementsByTagName('strong')[0].innerHtml);
infoCollection.add(info);
}
_controller.sink.add(infoCollection);
}
And I'm showing this images, titles, artists and rate by GridView like below
Widget _getWebtoonGridView() {
return StreamBuilder(
stream: _controller.stream.asBroadcastStream(),
builder: (BuildContext context, AsyncSnapshot<List> snapshot){
if(snapshot.hasError)
print(snapshot.error);
else if(snapshot.hasData){
return GridView.count(
crossAxisCount: 3,
childAspectRatio: 0.6,
children: List.generate(snapshot.data.length, (index){
return _getWebtoonInfo(index, snapshot.data[index]);
}),
);
}
else if(snapshot.connectionState != ConnectionState.done)
return Center(child: CircularProgressIndicator());
},
);
}
But "Stream has already been listened to" error is occurring continuously, what is the problem about my StreamController??
How can I fix it?
StackTrace
I/flutter (21411): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════ I/flutter
(21411): The following StateError was thrown building Expanded(flex:
1): I/flutter (21411): Bad state: Stream has already been listened to.
I/flutter (21411): I/flutter (21411): When the exception was thrown,
this was the stack: I/flutter (21411): #4
_StreamBuilderBaseState._subscribe (package:flutter/src/widgets/async.dart:135:37) I/flutter (21411): #5
_StreamBuilderBaseState.initState (package:flutter/src/widgets/async.dart:109:5) I/flutter (21411): #6
StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:3830:58) I/flutter
(21411): #7 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3696:5) I/flutter (21411):
8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14) I/flutter
(21411): #9 Element.updateChild
(package:flutter/src/widgets/framework.dart:2753:12)
StreamController variable
StreamController<List<List<String>>> _controller = StreamController<List<List<String>>>.broadcast();
gridview controller

whats the stacktrace (first few frames)?
– pskink
Jan 1 at 8:07
@pskink I added
– baeharam
Jan 1 at 8:10
how do you yourStreamController
?
– pskink
Jan 1 at 8:15
@pskink I added
– baeharam
Jan 1 at 8:19
so why do you need.asBroadcastStream()
? remove it,hot restart
your app and see what happens
– pskink
Jan 1 at 8:26
|
show 5 more comments
What I'm doing is to fetch cartoon list and show by GridView. Below code is fetching data
Future<void> _getWebtoonData() async {
var response;
if(_daysReceivedResponse[_pressedButtonDayIndex]){
response = _daysResponse[_pressedButtonDayIndex];
} else {
response= await http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week='+_currentWebtoonAddress);
_daysReceivedResponse[_pressedButtonDayIndex] = true;
_daysResponse[_pressedButtonDayIndex] = response;
}
dom.Document document = parser.parse(response.body);
final e1 = document.querySelectorAll('.img_list .thumb');
final e2 = document.querySelectorAll('.img_list .desc');
final e3 = document.querySelectorAll('.img_list .rating_type');
List<List<String>> infoCollection = List<List<String>>();
List<String> info = List<String>();
for(int i=0; i<e1.length; i++){
info.add(e1[i].getElementsByTagName('img')[0].attributes['src']);
info.add(e1[i].getElementsByTagName('a')[0].attributes['title']);
info.add(e2[i].getElementsByTagName('a')[0].innerHtml);
info.add(e3[i].getElementsByTagName('strong')[0].innerHtml);
infoCollection.add(info);
}
_controller.sink.add(infoCollection);
}
And I'm showing this images, titles, artists and rate by GridView like below
Widget _getWebtoonGridView() {
return StreamBuilder(
stream: _controller.stream.asBroadcastStream(),
builder: (BuildContext context, AsyncSnapshot<List> snapshot){
if(snapshot.hasError)
print(snapshot.error);
else if(snapshot.hasData){
return GridView.count(
crossAxisCount: 3,
childAspectRatio: 0.6,
children: List.generate(snapshot.data.length, (index){
return _getWebtoonInfo(index, snapshot.data[index]);
}),
);
}
else if(snapshot.connectionState != ConnectionState.done)
return Center(child: CircularProgressIndicator());
},
);
}
But "Stream has already been listened to" error is occurring continuously, what is the problem about my StreamController??
How can I fix it?
StackTrace
I/flutter (21411): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════ I/flutter
(21411): The following StateError was thrown building Expanded(flex:
1): I/flutter (21411): Bad state: Stream has already been listened to.
I/flutter (21411): I/flutter (21411): When the exception was thrown,
this was the stack: I/flutter (21411): #4
_StreamBuilderBaseState._subscribe (package:flutter/src/widgets/async.dart:135:37) I/flutter (21411): #5
_StreamBuilderBaseState.initState (package:flutter/src/widgets/async.dart:109:5) I/flutter (21411): #6
StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:3830:58) I/flutter
(21411): #7 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3696:5) I/flutter (21411):
8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14) I/flutter
(21411): #9 Element.updateChild
(package:flutter/src/widgets/framework.dart:2753:12)
StreamController variable
StreamController<List<List<String>>> _controller = StreamController<List<List<String>>>.broadcast();
gridview controller

What I'm doing is to fetch cartoon list and show by GridView. Below code is fetching data
Future<void> _getWebtoonData() async {
var response;
if(_daysReceivedResponse[_pressedButtonDayIndex]){
response = _daysResponse[_pressedButtonDayIndex];
} else {
response= await http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week='+_currentWebtoonAddress);
_daysReceivedResponse[_pressedButtonDayIndex] = true;
_daysResponse[_pressedButtonDayIndex] = response;
}
dom.Document document = parser.parse(response.body);
final e1 = document.querySelectorAll('.img_list .thumb');
final e2 = document.querySelectorAll('.img_list .desc');
final e3 = document.querySelectorAll('.img_list .rating_type');
List<List<String>> infoCollection = List<List<String>>();
List<String> info = List<String>();
for(int i=0; i<e1.length; i++){
info.add(e1[i].getElementsByTagName('img')[0].attributes['src']);
info.add(e1[i].getElementsByTagName('a')[0].attributes['title']);
info.add(e2[i].getElementsByTagName('a')[0].innerHtml);
info.add(e3[i].getElementsByTagName('strong')[0].innerHtml);
infoCollection.add(info);
}
_controller.sink.add(infoCollection);
}
And I'm showing this images, titles, artists and rate by GridView like below
Widget _getWebtoonGridView() {
return StreamBuilder(
stream: _controller.stream.asBroadcastStream(),
builder: (BuildContext context, AsyncSnapshot<List> snapshot){
if(snapshot.hasError)
print(snapshot.error);
else if(snapshot.hasData){
return GridView.count(
crossAxisCount: 3,
childAspectRatio: 0.6,
children: List.generate(snapshot.data.length, (index){
return _getWebtoonInfo(index, snapshot.data[index]);
}),
);
}
else if(snapshot.connectionState != ConnectionState.done)
return Center(child: CircularProgressIndicator());
},
);
}
But "Stream has already been listened to" error is occurring continuously, what is the problem about my StreamController??
How can I fix it?
StackTrace
I/flutter (21411): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════ I/flutter
(21411): The following StateError was thrown building Expanded(flex:
1): I/flutter (21411): Bad state: Stream has already been listened to.
I/flutter (21411): I/flutter (21411): When the exception was thrown,
this was the stack: I/flutter (21411): #4
_StreamBuilderBaseState._subscribe (package:flutter/src/widgets/async.dart:135:37) I/flutter (21411): #5
_StreamBuilderBaseState.initState (package:flutter/src/widgets/async.dart:109:5) I/flutter (21411): #6
StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:3830:58) I/flutter
(21411): #7 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3696:5) I/flutter (21411):
8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14) I/flutter
(21411): #9 Element.updateChild
(package:flutter/src/widgets/framework.dart:2753:12)
StreamController variable
StreamController<List<List<String>>> _controller = StreamController<List<List<String>>>.broadcast();
gridview controller

gridview controller

edited Jan 1 at 8:18
baeharam
asked Jan 1 at 8:02


baeharambaeharam
498
498
whats the stacktrace (first few frames)?
– pskink
Jan 1 at 8:07
@pskink I added
– baeharam
Jan 1 at 8:10
how do you yourStreamController
?
– pskink
Jan 1 at 8:15
@pskink I added
– baeharam
Jan 1 at 8:19
so why do you need.asBroadcastStream()
? remove it,hot restart
your app and see what happens
– pskink
Jan 1 at 8:26
|
show 5 more comments
whats the stacktrace (first few frames)?
– pskink
Jan 1 at 8:07
@pskink I added
– baeharam
Jan 1 at 8:10
how do you yourStreamController
?
– pskink
Jan 1 at 8:15
@pskink I added
– baeharam
Jan 1 at 8:19
so why do you need.asBroadcastStream()
? remove it,hot restart
your app and see what happens
– pskink
Jan 1 at 8:26
whats the stacktrace (first few frames)?
– pskink
Jan 1 at 8:07
whats the stacktrace (first few frames)?
– pskink
Jan 1 at 8:07
@pskink I added
– baeharam
Jan 1 at 8:10
@pskink I added
– baeharam
Jan 1 at 8:10
how do you your
StreamController
?– pskink
Jan 1 at 8:15
how do you your
StreamController
?– pskink
Jan 1 at 8:15
@pskink I added
– baeharam
Jan 1 at 8:19
@pskink I added
– baeharam
Jan 1 at 8:19
so why do you need
.asBroadcastStream()
? remove it, hot restart
your app and see what happens– pskink
Jan 1 at 8:26
so why do you need
.asBroadcastStream()
? remove it, hot restart
your app and see what happens– pskink
Jan 1 at 8:26
|
show 5 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993936%2fflutter-stream-has-already-been-listened-to-error-in-gridview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993936%2fflutter-stream-has-already-been-listened-to-error-in-gridview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
whats the stacktrace (first few frames)?
– pskink
Jan 1 at 8:07
@pskink I added
– baeharam
Jan 1 at 8:10
how do you your
StreamController
?– pskink
Jan 1 at 8:15
@pskink I added
– baeharam
Jan 1 at 8:19
so why do you need
.asBroadcastStream()
? remove it,hot restart
your app and see what happens– pskink
Jan 1 at 8:26