Flutter, StreamController is not working on fetching image from network












0















I'm practicing Stream and implemented simple app which fetches image and show to the screen.



Here is my code, but it doesn't show anything why??



I'm studying StreamController and it's usage, so I don't want to use Future or other Widget. This logic worked on simple counter app.



class MyAppPageState extends State<MyAppPage> {

StreamController<List<String>> _controller = StreamController<List<String>>();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(backgroundColor: Colors.orange),
body: Center(
child: StreamBuilder(
stream: _controller.stream,
builder: (BuildContext context, AsyncSnapshot snapshot) =>
Image.network(snapshot.data[0])
)
),
floatingActionButton: FloatingActionButton(
onPressed: () => _addDataToStream()
),
);
}

void _addDataToStream() {
http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week=mon')
.then((response){
dom.Document document = parser.parse(response.body);
final e = document.querySelectorAll('.img_list .thumb');
List<String> url = e.map((element){
return element.getElementsByTagName('img')[0]
.attributes['src'];
}).toList();
_controller.sink.add(url);
});
}

@override
void dispose() {
_controller.close();
super.dispose();
}
}









share|improve this question

























  • url has list of strings which mean the source address of image in webpage

    – baeharam
    Jan 2 at 10:21











  • [shared-comic.pstatic.net/thumb/webtoon/183559/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/648419/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/602910/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/654774/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/679519/thumbnail/…

    – baeharam
    Jan 2 at 10:41
















0















I'm practicing Stream and implemented simple app which fetches image and show to the screen.



Here is my code, but it doesn't show anything why??



I'm studying StreamController and it's usage, so I don't want to use Future or other Widget. This logic worked on simple counter app.



class MyAppPageState extends State<MyAppPage> {

StreamController<List<String>> _controller = StreamController<List<String>>();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(backgroundColor: Colors.orange),
body: Center(
child: StreamBuilder(
stream: _controller.stream,
builder: (BuildContext context, AsyncSnapshot snapshot) =>
Image.network(snapshot.data[0])
)
),
floatingActionButton: FloatingActionButton(
onPressed: () => _addDataToStream()
),
);
}

void _addDataToStream() {
http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week=mon')
.then((response){
dom.Document document = parser.parse(response.body);
final e = document.querySelectorAll('.img_list .thumb');
List<String> url = e.map((element){
return element.getElementsByTagName('img')[0]
.attributes['src'];
}).toList();
_controller.sink.add(url);
});
}

@override
void dispose() {
_controller.close();
super.dispose();
}
}









share|improve this question

























  • url has list of strings which mean the source address of image in webpage

    – baeharam
    Jan 2 at 10:21











  • [shared-comic.pstatic.net/thumb/webtoon/183559/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/648419/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/602910/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/654774/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/679519/thumbnail/…

    – baeharam
    Jan 2 at 10:41














0












0








0








I'm practicing Stream and implemented simple app which fetches image and show to the screen.



Here is my code, but it doesn't show anything why??



I'm studying StreamController and it's usage, so I don't want to use Future or other Widget. This logic worked on simple counter app.



class MyAppPageState extends State<MyAppPage> {

StreamController<List<String>> _controller = StreamController<List<String>>();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(backgroundColor: Colors.orange),
body: Center(
child: StreamBuilder(
stream: _controller.stream,
builder: (BuildContext context, AsyncSnapshot snapshot) =>
Image.network(snapshot.data[0])
)
),
floatingActionButton: FloatingActionButton(
onPressed: () => _addDataToStream()
),
);
}

void _addDataToStream() {
http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week=mon')
.then((response){
dom.Document document = parser.parse(response.body);
final e = document.querySelectorAll('.img_list .thumb');
List<String> url = e.map((element){
return element.getElementsByTagName('img')[0]
.attributes['src'];
}).toList();
_controller.sink.add(url);
});
}

@override
void dispose() {
_controller.close();
super.dispose();
}
}









share|improve this question
















I'm practicing Stream and implemented simple app which fetches image and show to the screen.



Here is my code, but it doesn't show anything why??



I'm studying StreamController and it's usage, so I don't want to use Future or other Widget. This logic worked on simple counter app.



class MyAppPageState extends State<MyAppPage> {

StreamController<List<String>> _controller = StreamController<List<String>>();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(backgroundColor: Colors.orange),
body: Center(
child: StreamBuilder(
stream: _controller.stream,
builder: (BuildContext context, AsyncSnapshot snapshot) =>
Image.network(snapshot.data[0])
)
),
floatingActionButton: FloatingActionButton(
onPressed: () => _addDataToStream()
),
);
}

void _addDataToStream() {
http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week=mon')
.then((response){
dom.Document document = parser.parse(response.body);
final e = document.querySelectorAll('.img_list .thumb');
List<String> url = e.map((element){
return element.getElementsByTagName('img')[0]
.attributes['src'];
}).toList();
_controller.sink.add(url);
});
}

@override
void dispose() {
_controller.close();
super.dispose();
}
}






dart stream flutter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 10:21









dshukertjr

1,9151829




1,9151829










asked Jan 2 at 9:32









baeharambaeharam

549




549













  • url has list of strings which mean the source address of image in webpage

    – baeharam
    Jan 2 at 10:21











  • [shared-comic.pstatic.net/thumb/webtoon/183559/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/648419/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/602910/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/654774/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/679519/thumbnail/…

    – baeharam
    Jan 2 at 10:41



















  • url has list of strings which mean the source address of image in webpage

    – baeharam
    Jan 2 at 10:21











  • [shared-comic.pstatic.net/thumb/webtoon/183559/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/648419/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/602910/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/654774/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/679519/thumbnail/…

    – baeharam
    Jan 2 at 10:41

















url has list of strings which mean the source address of image in webpage

– baeharam
Jan 2 at 10:21





url has list of strings which mean the source address of image in webpage

– baeharam
Jan 2 at 10:21













[shared-comic.pstatic.net/thumb/webtoon/183559/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/648419/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/602910/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/654774/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/679519/thumbnail/…

– baeharam
Jan 2 at 10:41





[shared-comic.pstatic.net/thumb/webtoon/183559/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/648419/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/602910/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/654774/thumbnail/…, shared-comic.pstatic.net/thumb/webtoon/679519/thumbnail/…

– baeharam
Jan 2 at 10:41












1 Answer
1






active

oldest

votes


















2














Your code works fine except with a little error.



When we opened the app for the first time, it'll show a NoSuchMethodError like this:



enter image description here



The reason was that we haven't checked our snapshot if it has already received a data or not.
We can use the initialData property to provide some initial data when there's no input from the stream.



initialData: <List<String>>,


We also need to write some if statements.



if (!snapshot.hasData) return Text('No Data');

if (snapshot.data.length == 0) return Text('No Data');

return Image.network(snapshot.data[0]);


I modified your code and created a BLoC class to be used.



This is the BLoC:



//somebloc.dart
import "dart:async";

class SomeBloc {

final _data = StreamController<List<String>>();
Stream<List<String>> get data => _data.stream;

final _url = StreamController<List<String>>();
Sink<List<String>> get urlIn => _url.sink;
Stream<List<String>> get urlOut => _url.stream;


SomeBloc() {
urlOut.listen(_handleData);
}

void _handleData(List<String> urlList) {
_data.add(urlList);
}

}


Modified main:



//main.dart
import "dart:async";

import 'package:http/http.dart' as http;
import 'package:html/parser.dart' as parser;
import 'package:html/dom.dart' as dom;

import "somebloc.dart"; // the bloc


...

class MyAppPageState extends State<MyAppPage> {

@override
Widget build(BuildContext context) {
SomeBloc bloc = SomeBloc();

return Scaffold(
appBar: AppBar(backgroundColor: Colors.orange),
body: Center(
child: StreamBuilder(
stream: bloc.data,
initialData: <List<String>>,
builder: (BuildContext context, AsyncSnapshot snapshot){

if (!snapshot.hasData) return Text('No Data');

if (snapshot.data.length == 0) return Text('No Data');

return Image.network(snapshot.data[0]);



}
)
),
floatingActionButton: FloatingActionButton(
onPressed: () => _addDataToStream()
),
);
}

void _addDataToStream() {

http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week=mon')
.then((response){
dom.Document document = parser.parse(response.body);
final e = document.querySelectorAll('.img_list .thumb');
List<String> url = e.map((element){
return element.getElementsByTagName('img')[0]
.attributes['src'];
}).toList();
bloc.urlIn.add(url);
});
}

}

...


If you are interested in using Streams, then I would recommend that you should use the rxdart package.



//somebloc.dart using rxdart
import "package:rxdart/rxdart.dart";
import "dart:async";

class SomeBloc {

final _data = BehaviorSubject<List<String>>(); // from rxdart
Stream<List<String>> get data => _data.stream;

final _url = StreamController<List<String>>();
Sink<List<String>> get urlIn => _url.sink;
Stream<List<String>> get urlOut => _url.stream;


SomeBloc() {
urlOut.listen(_handleData);
}

void _handleData(List<String> urlList) {
_data.add(urlList);
}

}


Here is the result:



enter image description here






share|improve this answer

























    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003969%2fflutter-streamcontroller-is-not-working-on-fetching-image-from-network%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Your code works fine except with a little error.



    When we opened the app for the first time, it'll show a NoSuchMethodError like this:



    enter image description here



    The reason was that we haven't checked our snapshot if it has already received a data or not.
    We can use the initialData property to provide some initial data when there's no input from the stream.



    initialData: <List<String>>,


    We also need to write some if statements.



    if (!snapshot.hasData) return Text('No Data');

    if (snapshot.data.length == 0) return Text('No Data');

    return Image.network(snapshot.data[0]);


    I modified your code and created a BLoC class to be used.



    This is the BLoC:



    //somebloc.dart
    import "dart:async";

    class SomeBloc {

    final _data = StreamController<List<String>>();
    Stream<List<String>> get data => _data.stream;

    final _url = StreamController<List<String>>();
    Sink<List<String>> get urlIn => _url.sink;
    Stream<List<String>> get urlOut => _url.stream;


    SomeBloc() {
    urlOut.listen(_handleData);
    }

    void _handleData(List<String> urlList) {
    _data.add(urlList);
    }

    }


    Modified main:



    //main.dart
    import "dart:async";

    import 'package:http/http.dart' as http;
    import 'package:html/parser.dart' as parser;
    import 'package:html/dom.dart' as dom;

    import "somebloc.dart"; // the bloc


    ...

    class MyAppPageState extends State<MyAppPage> {

    @override
    Widget build(BuildContext context) {
    SomeBloc bloc = SomeBloc();

    return Scaffold(
    appBar: AppBar(backgroundColor: Colors.orange),
    body: Center(
    child: StreamBuilder(
    stream: bloc.data,
    initialData: <List<String>>,
    builder: (BuildContext context, AsyncSnapshot snapshot){

    if (!snapshot.hasData) return Text('No Data');

    if (snapshot.data.length == 0) return Text('No Data');

    return Image.network(snapshot.data[0]);



    }
    )
    ),
    floatingActionButton: FloatingActionButton(
    onPressed: () => _addDataToStream()
    ),
    );
    }

    void _addDataToStream() {

    http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week=mon')
    .then((response){
    dom.Document document = parser.parse(response.body);
    final e = document.querySelectorAll('.img_list .thumb');
    List<String> url = e.map((element){
    return element.getElementsByTagName('img')[0]
    .attributes['src'];
    }).toList();
    bloc.urlIn.add(url);
    });
    }

    }

    ...


    If you are interested in using Streams, then I would recommend that you should use the rxdart package.



    //somebloc.dart using rxdart
    import "package:rxdart/rxdart.dart";
    import "dart:async";

    class SomeBloc {

    final _data = BehaviorSubject<List<String>>(); // from rxdart
    Stream<List<String>> get data => _data.stream;

    final _url = StreamController<List<String>>();
    Sink<List<String>> get urlIn => _url.sink;
    Stream<List<String>> get urlOut => _url.stream;


    SomeBloc() {
    urlOut.listen(_handleData);
    }

    void _handleData(List<String> urlList) {
    _data.add(urlList);
    }

    }


    Here is the result:



    enter image description here






    share|improve this answer






























      2














      Your code works fine except with a little error.



      When we opened the app for the first time, it'll show a NoSuchMethodError like this:



      enter image description here



      The reason was that we haven't checked our snapshot if it has already received a data or not.
      We can use the initialData property to provide some initial data when there's no input from the stream.



      initialData: <List<String>>,


      We also need to write some if statements.



      if (!snapshot.hasData) return Text('No Data');

      if (snapshot.data.length == 0) return Text('No Data');

      return Image.network(snapshot.data[0]);


      I modified your code and created a BLoC class to be used.



      This is the BLoC:



      //somebloc.dart
      import "dart:async";

      class SomeBloc {

      final _data = StreamController<List<String>>();
      Stream<List<String>> get data => _data.stream;

      final _url = StreamController<List<String>>();
      Sink<List<String>> get urlIn => _url.sink;
      Stream<List<String>> get urlOut => _url.stream;


      SomeBloc() {
      urlOut.listen(_handleData);
      }

      void _handleData(List<String> urlList) {
      _data.add(urlList);
      }

      }


      Modified main:



      //main.dart
      import "dart:async";

      import 'package:http/http.dart' as http;
      import 'package:html/parser.dart' as parser;
      import 'package:html/dom.dart' as dom;

      import "somebloc.dart"; // the bloc


      ...

      class MyAppPageState extends State<MyAppPage> {

      @override
      Widget build(BuildContext context) {
      SomeBloc bloc = SomeBloc();

      return Scaffold(
      appBar: AppBar(backgroundColor: Colors.orange),
      body: Center(
      child: StreamBuilder(
      stream: bloc.data,
      initialData: <List<String>>,
      builder: (BuildContext context, AsyncSnapshot snapshot){

      if (!snapshot.hasData) return Text('No Data');

      if (snapshot.data.length == 0) return Text('No Data');

      return Image.network(snapshot.data[0]);



      }
      )
      ),
      floatingActionButton: FloatingActionButton(
      onPressed: () => _addDataToStream()
      ),
      );
      }

      void _addDataToStream() {

      http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week=mon')
      .then((response){
      dom.Document document = parser.parse(response.body);
      final e = document.querySelectorAll('.img_list .thumb');
      List<String> url = e.map((element){
      return element.getElementsByTagName('img')[0]
      .attributes['src'];
      }).toList();
      bloc.urlIn.add(url);
      });
      }

      }

      ...


      If you are interested in using Streams, then I would recommend that you should use the rxdart package.



      //somebloc.dart using rxdart
      import "package:rxdart/rxdart.dart";
      import "dart:async";

      class SomeBloc {

      final _data = BehaviorSubject<List<String>>(); // from rxdart
      Stream<List<String>> get data => _data.stream;

      final _url = StreamController<List<String>>();
      Sink<List<String>> get urlIn => _url.sink;
      Stream<List<String>> get urlOut => _url.stream;


      SomeBloc() {
      urlOut.listen(_handleData);
      }

      void _handleData(List<String> urlList) {
      _data.add(urlList);
      }

      }


      Here is the result:



      enter image description here






      share|improve this answer




























        2












        2








        2







        Your code works fine except with a little error.



        When we opened the app for the first time, it'll show a NoSuchMethodError like this:



        enter image description here



        The reason was that we haven't checked our snapshot if it has already received a data or not.
        We can use the initialData property to provide some initial data when there's no input from the stream.



        initialData: <List<String>>,


        We also need to write some if statements.



        if (!snapshot.hasData) return Text('No Data');

        if (snapshot.data.length == 0) return Text('No Data');

        return Image.network(snapshot.data[0]);


        I modified your code and created a BLoC class to be used.



        This is the BLoC:



        //somebloc.dart
        import "dart:async";

        class SomeBloc {

        final _data = StreamController<List<String>>();
        Stream<List<String>> get data => _data.stream;

        final _url = StreamController<List<String>>();
        Sink<List<String>> get urlIn => _url.sink;
        Stream<List<String>> get urlOut => _url.stream;


        SomeBloc() {
        urlOut.listen(_handleData);
        }

        void _handleData(List<String> urlList) {
        _data.add(urlList);
        }

        }


        Modified main:



        //main.dart
        import "dart:async";

        import 'package:http/http.dart' as http;
        import 'package:html/parser.dart' as parser;
        import 'package:html/dom.dart' as dom;

        import "somebloc.dart"; // the bloc


        ...

        class MyAppPageState extends State<MyAppPage> {

        @override
        Widget build(BuildContext context) {
        SomeBloc bloc = SomeBloc();

        return Scaffold(
        appBar: AppBar(backgroundColor: Colors.orange),
        body: Center(
        child: StreamBuilder(
        stream: bloc.data,
        initialData: <List<String>>,
        builder: (BuildContext context, AsyncSnapshot snapshot){

        if (!snapshot.hasData) return Text('No Data');

        if (snapshot.data.length == 0) return Text('No Data');

        return Image.network(snapshot.data[0]);



        }
        )
        ),
        floatingActionButton: FloatingActionButton(
        onPressed: () => _addDataToStream()
        ),
        );
        }

        void _addDataToStream() {

        http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week=mon')
        .then((response){
        dom.Document document = parser.parse(response.body);
        final e = document.querySelectorAll('.img_list .thumb');
        List<String> url = e.map((element){
        return element.getElementsByTagName('img')[0]
        .attributes['src'];
        }).toList();
        bloc.urlIn.add(url);
        });
        }

        }

        ...


        If you are interested in using Streams, then I would recommend that you should use the rxdart package.



        //somebloc.dart using rxdart
        import "package:rxdart/rxdart.dart";
        import "dart:async";

        class SomeBloc {

        final _data = BehaviorSubject<List<String>>(); // from rxdart
        Stream<List<String>> get data => _data.stream;

        final _url = StreamController<List<String>>();
        Sink<List<String>> get urlIn => _url.sink;
        Stream<List<String>> get urlOut => _url.stream;


        SomeBloc() {
        urlOut.listen(_handleData);
        }

        void _handleData(List<String> urlList) {
        _data.add(urlList);
        }

        }


        Here is the result:



        enter image description here






        share|improve this answer















        Your code works fine except with a little error.



        When we opened the app for the first time, it'll show a NoSuchMethodError like this:



        enter image description here



        The reason was that we haven't checked our snapshot if it has already received a data or not.
        We can use the initialData property to provide some initial data when there's no input from the stream.



        initialData: <List<String>>,


        We also need to write some if statements.



        if (!snapshot.hasData) return Text('No Data');

        if (snapshot.data.length == 0) return Text('No Data');

        return Image.network(snapshot.data[0]);


        I modified your code and created a BLoC class to be used.



        This is the BLoC:



        //somebloc.dart
        import "dart:async";

        class SomeBloc {

        final _data = StreamController<List<String>>();
        Stream<List<String>> get data => _data.stream;

        final _url = StreamController<List<String>>();
        Sink<List<String>> get urlIn => _url.sink;
        Stream<List<String>> get urlOut => _url.stream;


        SomeBloc() {
        urlOut.listen(_handleData);
        }

        void _handleData(List<String> urlList) {
        _data.add(urlList);
        }

        }


        Modified main:



        //main.dart
        import "dart:async";

        import 'package:http/http.dart' as http;
        import 'package:html/parser.dart' as parser;
        import 'package:html/dom.dart' as dom;

        import "somebloc.dart"; // the bloc


        ...

        class MyAppPageState extends State<MyAppPage> {

        @override
        Widget build(BuildContext context) {
        SomeBloc bloc = SomeBloc();

        return Scaffold(
        appBar: AppBar(backgroundColor: Colors.orange),
        body: Center(
        child: StreamBuilder(
        stream: bloc.data,
        initialData: <List<String>>,
        builder: (BuildContext context, AsyncSnapshot snapshot){

        if (!snapshot.hasData) return Text('No Data');

        if (snapshot.data.length == 0) return Text('No Data');

        return Image.network(snapshot.data[0]);



        }
        )
        ),
        floatingActionButton: FloatingActionButton(
        onPressed: () => _addDataToStream()
        ),
        );
        }

        void _addDataToStream() {

        http.get('https://comic.naver.com/webtoon/weekdayList.nhn?week=mon')
        .then((response){
        dom.Document document = parser.parse(response.body);
        final e = document.querySelectorAll('.img_list .thumb');
        List<String> url = e.map((element){
        return element.getElementsByTagName('img')[0]
        .attributes['src'];
        }).toList();
        bloc.urlIn.add(url);
        });
        }

        }

        ...


        If you are interested in using Streams, then I would recommend that you should use the rxdart package.



        //somebloc.dart using rxdart
        import "package:rxdart/rxdart.dart";
        import "dart:async";

        class SomeBloc {

        final _data = BehaviorSubject<List<String>>(); // from rxdart
        Stream<List<String>> get data => _data.stream;

        final _url = StreamController<List<String>>();
        Sink<List<String>> get urlIn => _url.sink;
        Stream<List<String>> get urlOut => _url.stream;


        SomeBloc() {
        urlOut.listen(_handleData);
        }

        void _handleData(List<String> urlList) {
        _data.add(urlList);
        }

        }


        Here is the result:



        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 3 at 0:26

























        answered Jan 2 at 15:03









        Jerome EscalanteJerome Escalante

        790149




        790149
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003969%2fflutter-streamcontroller-is-not-working-on-fetching-image-from-network%23new-answer', 'question_page');
            }
            );

            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







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas