Can we use the equatable on navigation, form validation?…..also explain me on which cases we can use equatble in which we can’t use it
i am a beginner in BLoC so i need to know the cases in which we can use eqautable package in BLoC
Can we use the equatable on navigation, form validation?…..also explain me on which cases we can use equatble in which we can’t use it
i am a beginner in BLoC so i need to know the cases in which we can use eqautable package in BLoC
2
Answers
Your question is not very specific. So in general, you would use equatable if you compare to data class objects. Or in other words, if you intend to compare instances of a class you would declare them as Equatable.
Example: You have a class rectangle and you want to check if rectangle A has the same size as rectangle B => A == B?
If on the other hand you only compare variables within the class, then you don’t need Equatable
Example: you only have comparisons of the kind A.length == B.length
With regards to Bloc, if I am not mistaken you would use Equatable if you update the same state. The opposite makes this easier to understand: Without Equatable you need to change the state (and not only the data within the state) in order to update your screen. If you want to update your same state eg MyFormUpdate with new data, then you would need to yield MyFormInProgress in between. Yielding 2 MyFormUpdate states directly after one another, would only show the data of the first state
Equatable
is highly recommended to use if you are emitting a newstate
by copying the earlier state. By default the new state is not emitted if its same as the earlier state. UsingEquatable
is an easier way to deal with such conditions.Consider the following case of
LoginFormState
withusername
andpassword
. Everytime the username or password is changed, you can emit a new state using thecopyWith()
method.