'When to use .add() and when to use emit() in Flutter Bloc?
I am new to Bloc in flutter, any one can please explain when should I use add() and when to use emit in Blocs?
Solution 1:[1]
Use emit when you want a new state for your bloc.
Use add when you want your bloc to handle a new event.
See the Timer tutorial has an example.
Solution 2:[2]
You should always use emit, flutter bloc was upgrade to extends Cubit class and Cubit uses emit. Add was old usage.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mario Daglio |
| Solution 2 | Hrvoje ?ukman |
