Flutter: My list view is not updated when I modify an itemFlutter: Best Practices of Calling Async Codes from UIFlutter List View error in building list viewFlutter : Bad state: Stream has already been listened toPrepend list view items while maintaining scroll view offset in FlutterFlutter Remove list itemFlutter Edit List ItemWhen and Where to call API in flutterListView not displaying item with BLoC patternHow I can put Widget above Widget using List<Widget> widget in Flutter?How to make Flutter DropDownButton's items window scrollable?

Inadvertently nuked my disk permission structure - why?

How do I run a game when my PCs have different approaches to combat?

expansion with *.txt in the shell doesn't work if no .txt file exists

Send single HTML mail

Why is chess failing to attract big name sponsors?

Q: What is a Checkmate Word™?

Why is a dedicated QA team member necessary?

Why can't my huge trees be chopped down?

What does ものと見て, mean?

How to judge a Ph.D. applicant that arrives "out of thin air"

How important is a good quality camera for good photography?

Why are there not any MRI machines available in Interstellar?

Terence Tao - type books in other fields?

Why did Saturn V not head straight to the moon?

Does academia have a lazy work culture?

How do professional electronic musicians/sound engineers combat listening fatigue?

What to do when you reach a conclusion and find out later on that someone else already did?

What exactly makes a General Products hull nearly indestructible?

401(k) investment after being fired. Do I own it?

What does "see" in "the Holy See" mean?

How can I receive packages while in France?

What does "a good player" mean in the movie Training day?

Move a group of files, prompting the user for confirmation for every file

Convert a string like 4h53m12s to a total number of seconds in JavaScript



Flutter: My list view is not updated when I modify an item


Flutter: Best Practices of Calling Async Codes from UIFlutter List View error in building list viewFlutter : Bad state: Stream has already been listened toPrepend list view items while maintaining scroll view offset in FlutterFlutter Remove list itemFlutter Edit List ItemWhen and Where to call API in flutterListView not displaying item with BLoC patternHow I can put Widget above Widget using List<Widget> widget in Flutter?How to make Flutter DropDownButton's items window scrollable?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am developing a 'todo' flutter app using BloC Architecture pattern.



My 'Home' ui displays todo list, and user can click the item's button to change the status from "todo" to "complete".



When an item is completed, it should display with another color distinct from other todos not completed.



But when I click the "complete" button, the list view is not updated.



Below is my UI code:



class HomePage extends StatelessWidget 
final TodoRepository _todoRepository;
final HomeBloc bloc;

HomePage(this._todoRepository) : this.bloc = HomeBloc(_todoRepository);

@override
Widget build(BuildContext context)
return Scaffold(
body: Center(
child: StreamBuilder<List<Task>>(
stream: bloc.todos,
builder: (context, snapshot)
return ListView(
children: snapshot.data.map(_buildItem).toList(),
);
),
),
);


Widget _buildItem(Todo todo)
if (todo.complete)
return completed(todo);
else
return inCompleted(todo);



Widget inCompleted(Todo todo)
return MaterialButton(
textColor: Colors.white,
color: Colors.green,
child: Text("Complete"),
onPressed: ()
bloc.done.add(todo);

);


Widget completed(Todo todo)
return MaterialButton(
textColor: Colors.white,
color: Colors.red,
child: Text("Cancel"),
onPressed: ()
bloc.done.add(todo);

);





And here is my BloC class:



class HomeBloc 

final _getTodosSubject = PublishSubject<List<Todo>>();
final _doneTodoSubject = PublishSubject<Todo>();
final _cancelTodoSubject = PublishSubject<Todo>();

final TodoRepository _todoRepository;

var _todos = <Todo>[];

Stream<List<Todo>> get todos => _getTodosSubject.stream;

Sink<Todo> get done => _doneTodoSubject.sink;

Sink<Todo> get cancel => _doneTodoSubject.sink;

HomeBloc(this._todoRepository)
_getTodos().then((_)
_getTodosSubject.add(_todos);
);

_doneTodoSubject.listen(_doneTodo);

_cancelTodoSubject.listen(_cancelTodo);


Future<Null> _getTodos() async
await _todoRepository.getAll().then((list)
_todos = list;
);


void _doneTodo(Todo todo)
todo.complete = true;
_update(todo);


void _cancelTodo(Todo todo) async
todo.complete = false;
_update(todo);


void _update(Todo todo) async
await _todoRepository.save(todo);
_getTodos();












share|improve this question






























    0















    I am developing a 'todo' flutter app using BloC Architecture pattern.



    My 'Home' ui displays todo list, and user can click the item's button to change the status from "todo" to "complete".



    When an item is completed, it should display with another color distinct from other todos not completed.



    But when I click the "complete" button, the list view is not updated.



    Below is my UI code:



    class HomePage extends StatelessWidget 
    final TodoRepository _todoRepository;
    final HomeBloc bloc;

    HomePage(this._todoRepository) : this.bloc = HomeBloc(_todoRepository);

    @override
    Widget build(BuildContext context)
    return Scaffold(
    body: Center(
    child: StreamBuilder<List<Task>>(
    stream: bloc.todos,
    builder: (context, snapshot)
    return ListView(
    children: snapshot.data.map(_buildItem).toList(),
    );
    ),
    ),
    );


    Widget _buildItem(Todo todo)
    if (todo.complete)
    return completed(todo);
    else
    return inCompleted(todo);



    Widget inCompleted(Todo todo)
    return MaterialButton(
    textColor: Colors.white,
    color: Colors.green,
    child: Text("Complete"),
    onPressed: ()
    bloc.done.add(todo);

    );


    Widget completed(Todo todo)
    return MaterialButton(
    textColor: Colors.white,
    color: Colors.red,
    child: Text("Cancel"),
    onPressed: ()
    bloc.done.add(todo);

    );





    And here is my BloC class:



    class HomeBloc 

    final _getTodosSubject = PublishSubject<List<Todo>>();
    final _doneTodoSubject = PublishSubject<Todo>();
    final _cancelTodoSubject = PublishSubject<Todo>();

    final TodoRepository _todoRepository;

    var _todos = <Todo>[];

    Stream<List<Todo>> get todos => _getTodosSubject.stream;

    Sink<Todo> get done => _doneTodoSubject.sink;

    Sink<Todo> get cancel => _doneTodoSubject.sink;

    HomeBloc(this._todoRepository)
    _getTodos().then((_)
    _getTodosSubject.add(_todos);
    );

    _doneTodoSubject.listen(_doneTodo);

    _cancelTodoSubject.listen(_cancelTodo);


    Future<Null> _getTodos() async
    await _todoRepository.getAll().then((list)
    _todos = list;
    );


    void _doneTodo(Todo todo)
    todo.complete = true;
    _update(todo);


    void _cancelTodo(Todo todo) async
    todo.complete = false;
    _update(todo);


    void _update(Todo todo) async
    await _todoRepository.save(todo);
    _getTodos();












    share|improve this question


























      0












      0








      0


      1






      I am developing a 'todo' flutter app using BloC Architecture pattern.



      My 'Home' ui displays todo list, and user can click the item's button to change the status from "todo" to "complete".



      When an item is completed, it should display with another color distinct from other todos not completed.



      But when I click the "complete" button, the list view is not updated.



      Below is my UI code:



      class HomePage extends StatelessWidget 
      final TodoRepository _todoRepository;
      final HomeBloc bloc;

      HomePage(this._todoRepository) : this.bloc = HomeBloc(_todoRepository);

      @override
      Widget build(BuildContext context)
      return Scaffold(
      body: Center(
      child: StreamBuilder<List<Task>>(
      stream: bloc.todos,
      builder: (context, snapshot)
      return ListView(
      children: snapshot.data.map(_buildItem).toList(),
      );
      ),
      ),
      );


      Widget _buildItem(Todo todo)
      if (todo.complete)
      return completed(todo);
      else
      return inCompleted(todo);



      Widget inCompleted(Todo todo)
      return MaterialButton(
      textColor: Colors.white,
      color: Colors.green,
      child: Text("Complete"),
      onPressed: ()
      bloc.done.add(todo);

      );


      Widget completed(Todo todo)
      return MaterialButton(
      textColor: Colors.white,
      color: Colors.red,
      child: Text("Cancel"),
      onPressed: ()
      bloc.done.add(todo);

      );





      And here is my BloC class:



      class HomeBloc 

      final _getTodosSubject = PublishSubject<List<Todo>>();
      final _doneTodoSubject = PublishSubject<Todo>();
      final _cancelTodoSubject = PublishSubject<Todo>();

      final TodoRepository _todoRepository;

      var _todos = <Todo>[];

      Stream<List<Todo>> get todos => _getTodosSubject.stream;

      Sink<Todo> get done => _doneTodoSubject.sink;

      Sink<Todo> get cancel => _doneTodoSubject.sink;

      HomeBloc(this._todoRepository)
      _getTodos().then((_)
      _getTodosSubject.add(_todos);
      );

      _doneTodoSubject.listen(_doneTodo);

      _cancelTodoSubject.listen(_cancelTodo);


      Future<Null> _getTodos() async
      await _todoRepository.getAll().then((list)
      _todos = list;
      );


      void _doneTodo(Todo todo)
      todo.complete = true;
      _update(todo);


      void _cancelTodo(Todo todo) async
      todo.complete = false;
      _update(todo);


      void _update(Todo todo) async
      await _todoRepository.save(todo);
      _getTodos();












      share|improve this question
















      I am developing a 'todo' flutter app using BloC Architecture pattern.



      My 'Home' ui displays todo list, and user can click the item's button to change the status from "todo" to "complete".



      When an item is completed, it should display with another color distinct from other todos not completed.



      But when I click the "complete" button, the list view is not updated.



      Below is my UI code:



      class HomePage extends StatelessWidget 
      final TodoRepository _todoRepository;
      final HomeBloc bloc;

      HomePage(this._todoRepository) : this.bloc = HomeBloc(_todoRepository);

      @override
      Widget build(BuildContext context)
      return Scaffold(
      body: Center(
      child: StreamBuilder<List<Task>>(
      stream: bloc.todos,
      builder: (context, snapshot)
      return ListView(
      children: snapshot.data.map(_buildItem).toList(),
      );
      ),
      ),
      );


      Widget _buildItem(Todo todo)
      if (todo.complete)
      return completed(todo);
      else
      return inCompleted(todo);



      Widget inCompleted(Todo todo)
      return MaterialButton(
      textColor: Colors.white,
      color: Colors.green,
      child: Text("Complete"),
      onPressed: ()
      bloc.done.add(todo);

      );


      Widget completed(Todo todo)
      return MaterialButton(
      textColor: Colors.white,
      color: Colors.red,
      child: Text("Cancel"),
      onPressed: ()
      bloc.done.add(todo);

      );





      And here is my BloC class:



      class HomeBloc 

      final _getTodosSubject = PublishSubject<List<Todo>>();
      final _doneTodoSubject = PublishSubject<Todo>();
      final _cancelTodoSubject = PublishSubject<Todo>();

      final TodoRepository _todoRepository;

      var _todos = <Todo>[];

      Stream<List<Todo>> get todos => _getTodosSubject.stream;

      Sink<Todo> get done => _doneTodoSubject.sink;

      Sink<Todo> get cancel => _doneTodoSubject.sink;

      HomeBloc(this._todoRepository)
      _getTodos().then((_)
      _getTodosSubject.add(_todos);
      );

      _doneTodoSubject.listen(_doneTodo);

      _cancelTodoSubject.listen(_cancelTodo);


      Future<Null> _getTodos() async
      await _todoRepository.getAll().then((list)
      _todos = list;
      );


      void _doneTodo(Todo todo)
      todo.complete = true;
      _update(todo);


      void _cancelTodo(Todo todo) async
      todo.complete = false;
      _update(todo);


      void _update(Todo todo) async
      await _todoRepository.save(todo);
      _getTodos();









      dart flutter bloc






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 16:40







      yoonhok

















      asked Mar 26 at 16:33









      yoonhokyoonhok

      5721 gold badge5 silver badges17 bronze badges




      5721 gold badge5 silver badges17 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          1














          It's because you don't "refresh" your list after calling getTodos() here's the modification:



          HomeBloc(this._todoRepository) 
          _getTodos() //Remove the adding part it's done in the function

          _doneTodoSubject.listen(_doneTodo);

          _cancelTodoSubject.listen(_cancelTodo);


          Future<Null> _getTodos() async
          await _todoRepository.getAll().then((list)
          _todos = list;
          _getTodosSubject.add(list); //You can actually remove the buffer _todos object
          );



          As I mention in the comment you can remove the _todos buffer but I don't want to refract to much you code.



          With these few adjustents it's should work.
          Hope it's help !!






          share|improve this answer























          • Thanks, it works! _getTodosSubject.sink.add(list); works too. Do you know what differences between these?

            – yoonhok
            Mar 26 at 16:53










          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%2f55362073%2fflutter-my-list-view-is-not-updated-when-i-modify-an-item%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









          1














          It's because you don't "refresh" your list after calling getTodos() here's the modification:



          HomeBloc(this._todoRepository) 
          _getTodos() //Remove the adding part it's done in the function

          _doneTodoSubject.listen(_doneTodo);

          _cancelTodoSubject.listen(_cancelTodo);


          Future<Null> _getTodos() async
          await _todoRepository.getAll().then((list)
          _todos = list;
          _getTodosSubject.add(list); //You can actually remove the buffer _todos object
          );



          As I mention in the comment you can remove the _todos buffer but I don't want to refract to much you code.



          With these few adjustents it's should work.
          Hope it's help !!






          share|improve this answer























          • Thanks, it works! _getTodosSubject.sink.add(list); works too. Do you know what differences between these?

            – yoonhok
            Mar 26 at 16:53















          1














          It's because you don't "refresh" your list after calling getTodos() here's the modification:



          HomeBloc(this._todoRepository) 
          _getTodos() //Remove the adding part it's done in the function

          _doneTodoSubject.listen(_doneTodo);

          _cancelTodoSubject.listen(_cancelTodo);


          Future<Null> _getTodos() async
          await _todoRepository.getAll().then((list)
          _todos = list;
          _getTodosSubject.add(list); //You can actually remove the buffer _todos object
          );



          As I mention in the comment you can remove the _todos buffer but I don't want to refract to much you code.



          With these few adjustents it's should work.
          Hope it's help !!






          share|improve this answer























          • Thanks, it works! _getTodosSubject.sink.add(list); works too. Do you know what differences between these?

            – yoonhok
            Mar 26 at 16:53













          1












          1








          1







          It's because you don't "refresh" your list after calling getTodos() here's the modification:



          HomeBloc(this._todoRepository) 
          _getTodos() //Remove the adding part it's done in the function

          _doneTodoSubject.listen(_doneTodo);

          _cancelTodoSubject.listen(_cancelTodo);


          Future<Null> _getTodos() async
          await _todoRepository.getAll().then((list)
          _todos = list;
          _getTodosSubject.add(list); //You can actually remove the buffer _todos object
          );



          As I mention in the comment you can remove the _todos buffer but I don't want to refract to much you code.



          With these few adjustents it's should work.
          Hope it's help !!






          share|improve this answer













          It's because you don't "refresh" your list after calling getTodos() here's the modification:



          HomeBloc(this._todoRepository) 
          _getTodos() //Remove the adding part it's done in the function

          _doneTodoSubject.listen(_doneTodo);

          _cancelTodoSubject.listen(_cancelTodo);


          Future<Null> _getTodos() async
          await _todoRepository.getAll().then((list)
          _todos = list;
          _getTodosSubject.add(list); //You can actually remove the buffer _todos object
          );



          As I mention in the comment you can remove the _todos buffer but I don't want to refract to much you code.



          With these few adjustents it's should work.
          Hope it's help !!







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 26 at 16:45









          FerdiFerdi

          4652 silver badges7 bronze badges




          4652 silver badges7 bronze badges












          • Thanks, it works! _getTodosSubject.sink.add(list); works too. Do you know what differences between these?

            – yoonhok
            Mar 26 at 16:53

















          • Thanks, it works! _getTodosSubject.sink.add(list); works too. Do you know what differences between these?

            – yoonhok
            Mar 26 at 16:53
















          Thanks, it works! _getTodosSubject.sink.add(list); works too. Do you know what differences between these?

          – yoonhok
          Mar 26 at 16:53





          Thanks, it works! _getTodosSubject.sink.add(list); works too. Do you know what differences between these?

          – yoonhok
          Mar 26 at 16:53








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          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%2f55362073%2fflutter-my-list-view-is-not-updated-when-i-modify-an-item%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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해