0

Maybe my question is a nooby one, but i really try to understand how to implement the following operations:

  1. How to add item for a list without the need of rebuilding all list.
  2. How to update a class instance property value.
  3. Does BLoCProvider used only once in a class?

===> I'm asking those question because i see that BLoC working with 'Equatable' and that in a the state class there is always a need to bring default value to the state we provide to the view class.

  • Another Question (what change the view and operate the state): Does i need to bring always a list in order for example to update an item from the list or only changing the state+emit(in cubit) will change the state of the application, maybe it realted to BLocListener?
AIX
  • 61
  • 2
  • By rebuilding do you mean re-instantiate the list or rebuilding the widget? – Gabriel Costache Nov 25 '20 at 09:57
  • Like using for example audioplayers package and run several players. – AIX Nov 25 '20 at 09:57
  • @GabrielCostache re-instantiat. Because if i have nested class and currentlly it playing the audio, if i rebuild all again, it will need to re-run the audioplayers probably. – AIX Nov 25 '20 at 09:59
  • Your reply isn't clear, can you try to be more detailed? Do you mean rebuilding all the widgets on the UI or creating a new List with that specific item added in it? – Gabriel Costache Nov 25 '20 at 09:59
  • @GabrielCostache 1. I have a list contains items when each item contains audioplayer and other widget that i can modify. 2. If i rebuild the the list (as creating using BLoC in general) all the latest states changed on each item will be set to default right? because i rebuild all of them again. ==> I want to add an item without rebuilding all the items / without losing the states of the other items (which contains something that can be changed by the user). I.E, not starting each item change "from scratch". – AIX Nov 25 '20 at 10:08
  • You should not lose state in a re-build. That is the whole point of stateful vs stateless widgets. – nvoigt Nov 25 '20 at 10:30
  • @nvoigt If i'm using stateless with BLoC i will lose the state on each rebuild no? So i have to use statefull for this use case and i won't lose the state? – AIX Nov 25 '20 at 11:42
  • 1
    That is the point of "state", to survive a rebuild. Yes. – nvoigt Nov 25 '20 at 12:29
  • If I my enter this discussion, it is a good question what happens in case of using bloc. So given I have those players as items of a list, each having a certain state, if I want to send a new state via bloc, I first have to send an intermediate state like "in progress". So I assume, the state of those players is lost with sending the new state, right? So one would need to send the state of each player with the event to the bloc and then back to the UI with the new state? – w461 Nov 25 '20 at 13:25
  • @nvoigt so only Statful option can be used with audioplayers for example. and using copyWith inorder to change class instance property values in the Statful class right? – AIX Nov 25 '20 at 14:33
  • @w461 I think with Statful class the state will stay as I understand, we mostly see stateless class as recommended class. But if we want to preserve a state, especially of a audio(running state) and/or widgets, we have to use Statful. – AIX Nov 25 '20 at 14:36
  • This is true for anything outside the BlocBuilder. However, inside the BlocBuilder, I am not certain whether the state is preserved when you send an intermediate state for refreshing. But you can check it in your code and tell us your result here :) – w461 Nov 25 '20 at 16:48

0 Answers0