title: Use Cubit for Flutter form
body: <p>I’m trying to use Cubit state management for a form (validation and submit). Is there any example I can follow?</p>
  <p>I have already tried to implement it and it works, but every time there is an error, it shows me the form again with empty fields because the widget is repainted with initial data. How can I solve it?</p>
  <p>Here my Cubit consumer code on the form:</p>
  <pre><code>BlocConsumer&lt;LoginCubit, LoginState&gt; buildLoginCard(BuildContext context) {
    return BlocConsumer&lt;LoginCubit, LoginState&gt;(
      listener: (context, state) {
        if (state is LoginError) {
          Scaffold.of(context).showSnackBar(
            SnackBar(
              content: Text(state.message),
              backgroundColor: Colors.red,
            ),
          );
        } else if (state is LoginSuccess) {
          BlocProvider.of&lt;AuthCubit&gt;(context).autoLogin();
        }
      },
      builder: (context, state) {
        if (state is LoginInProgress) {
          return LoadingWidget();
        } else {
          return LoginCardWidget();
        }
      },
    );
  }
  </code></pre>