Is your feature request related to a problem? Please describe.
A new state will not be emitted if the previous_state == new_state. While this is usually the desired behavior. This doesn't work when I am using the super_enum package (https://pub.dev/packages/super_enum) to represent my different states. Adding this option doesn't do too much harm and it gives the user mode control of the behavior of the cubit.
Describe the solution you'd like
Allow force emitting a state through an optional parameter in the emit method.
Hi @jinyus 馃憢
Thanks so much for opening an issue!
Can you please provide a link to a sample app which illustrates the issue you鈥檙e facing? Thanks 馃檹
I am making the example code and I want to know when emit has fired...does the onChange in BlocObserver indicates when a state has been emitted?
Yup onChange is called when a new state is emitted 馃憤
here is the example code: https://github.com/jinyus/cubit_super_enum_sample
Hi @jinyus this is because you are mutating the state rather than emitting a new instance.
I modified
var currentMessages = s.messages;
to
final currentMessages = List.of(s.messages);
and that resulted in:
$ dart lib/main.dart
lib/main.dart: Warning: Interpreting this as package URI, 'package:cubit_superenum_sample/main.dart'.
onChange -- cubit: LoggerCubit, change: Change { currentState: Initial(), nextState: Loaded(messages: [hello 1]) }
onChange -- cubit: LoggerCubit, change: Change { currentState: Loaded(messages: [hello 1]), nextState: Loaded(messages: [hello 1, hello 2]) }
onChange -- cubit: LoggerCubit, change: Change { currentState: Loaded(messages: [hello 1, hello 2]), nextState: Loaded(messages: [hello 1, hello 2, hello 3]) }
onChange -- cubit: LoggerCubit, change: Change { currentState: Loaded(messages: [hello 1, hello 2, hello 3]), nextState: Loaded(messages: [hello 1, hello 2, hello 3, hello 4]) }
Hope that helps 馃憤
Thanks @felangel , works as expected now.