How to use Cubit when working with the form?

188 Views Asked by At

I have a feedback screen. The themes for this form are loaded with a separate query. I understand correctly that when using any state manager, in this case Cubit I have to give up setState() and create 3 Cubit:

  1. Cubit to get a list of themes (States: Download/Data/Error).
  2. Cubit to select themes (States: theme selected).
  3. Cubit to send messages (States: send/send/error).

If you do everything as I wrote above (create 3 cubit) then wouldn’t it be redundant work?

1

There are 1 best solutions below

0
Vladyslav Ulianytskyi On

Indeed, the description looks like redundant work.

the first two points must be in the same qubit. you use the same data that you received, displayed to the user, and handle the user's interaction with them. it is logical that this is one сubit.

sending messages should preferably be in another сubit if:

  • this logic (sending and rebuilding the UI part) is used in another screen
  • sending messages rebuild UI part of this screen separately from the first two points.

if in the third point you send data, such as the theme selected by the user, then this should also definitely be in the same qubit. but even if this is other data, but sending messages is ONLY on this screen, then this logic may well live in this qubit too.