title: How to change event in BLoC in Flutter?
body: <p>I have an app which creates a 2FA totp key. When I click &quot;Add&quot; button when a form is not filled, it shows an Alert Dialog. If I click it second time (still, the form isn't filled), the alert dialog doesn't show up. How do I show the Alert Dialog for the infinite times? I used BlocConsumer to listen to changes and show the Alert Dialog when the state is ManualInputError, and a BlocBuilder to show the actual TextButton.</p>
  <p><a href="https://i.stack.imgur.com/nfOBz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nfOBz.png" alt="Image" /></a></p>
  <h2>Code:</h2>
  <pre><code>import 'dart:io';
  
  import 'package:duckie/blocs/manual_input/manual_input_bloc.dart';
  import 'package:duckie/screens/widgets/alert_dialog.dart';
  import 'package:duckie/screens/widgets/custom_text_field.dart';
  import 'package:duckie/shared/text_styles.dart';
  import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  
  import 'package:easy_localization/easy_localization.dart';
  import 'package:flutter_bloc/flutter_bloc.dart';
  
  class ManualInputScreen extends StatefulWidget {
    @override
    _ManualInputScreenState createState() =&gt; _ManualInputScreenState();
  }
  
  class _ManualInputScreenState extends State&lt;ManualInputScreen&gt; {
    String secretKey;
    String issuer;
    String accountName;
    String numberOfDigits = '6';
    String timeStep = '30';
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(
            'manual-input',
            style: TextStyles.appBarText,
          ).tr(),
          centerTitle: true,
          elevation: 0.0,
          actions: [
            BlocConsumer&lt;ManualInputBloc, ManualInputState&gt;(
              listener: (context, state) {
                if (state is ManualInputError) {
                  Platform.isAndroid
                      ? CustomAlertDialog.showAndroidAlertDialog(
                          context,
                          state.alertDialogErrorTitle,
                          state.alertDialogErrorContent)
                      : CustomAlertDialog.showIosAlertDialog(
                          context,
                          state.alertDialogErrorTitle,
                          state.alertDialogErrorContent);
  
                  BlocProvider.of&lt;ManualInputBloc&gt;(context).close();
                }
              },
              builder: (context, state) {
                if (state is ManualInputInitial || state is ManualInputFinal) {
                  return TextButton(
                    onPressed: () {
                      BlocProvider.of&lt;ManualInputBloc&gt;(context).add(
                          GetFormTextEvent(secretKey, issuer, accountName,
                              numberOfDigits, timeStep));
                    },
                    child: Text('add').tr(),
                  );
                }
                return TextButton(
                  onPressed: () {},
                  child: Text('add').tr(),
                );
              },
            )
          ],
        ),
        body: Container(
          padding: EdgeInsets.all(8.0),
          child: ListView(
            children: [
              CustomTextField(
                labelText: 'secret-key'.tr(),
                onChanged: (value) {
                  setState(() {
                    secretKey = value;
                  });
                },
              ),
              SizedBox(
                height: 8.0,
              ),
              CustomTextField(
                labelText: 'issuer'.tr(),
                onChanged: (value) {
                  issuer = value;
                },
              ),
              SizedBox(
                height: 8.0,
              ),
              CustomTextField(
                labelText: 'account-name'.tr(),
                onChanged: (value) {
                  setState(() {
                    accountName = value;
                  });
                },
              ),
              SizedBox(
                height: 8.0,
              ),
              Platform.isAndroid
                  ? ListBody(
                      children: [
                        Text('number-of-digits').tr(),
                        SizedBox(
                          height: 5.0,
                        ),
                        DropdownButton(
                          value: numberOfDigits,
                          onChanged: (value) {
                            setState(() {
                              numberOfDigits = value;
                            });
                          },
                          items: [
                            DropdownMenuItem(
                              value: '6',
                              child: Text('6'),
                            ),
                            DropdownMenuItem(
                              value: '8',
                              child: Text('8'),
                            ),
                          ],
                        )
                      ],
                    )
                  : ListBody(
                      children: [
                        Text('number-of-digits').tr(),
                        SizedBox(
                          height: 5.0,
                        ),
                        CupertinoSegmentedControl(
                          groupValue: numberOfDigits,
                          children: {
                            '6': Text('6'),
                            '8': Text('8'),
                          },
                          onValueChanged: (value) {
                            setState(() {
                              numberOfDigits = value;
                            });
                          },
                        ),
                      ],
                    ),
              SizedBox(
                height: 8.0,
              ),
              Platform.isAndroid
                  ? ListBody(
                      children: [
                        Text('time-step').tr(),
                        SizedBox(
                          height: 5.0,
                        ),
                        DropdownButton(
                          value: timeStep,
                          onChanged: (value) {
                            setState(() {
                              timeStep = value;
                            });
                          },
                          items: [
                            DropdownMenuItem(
                              value: '30',
                              child: Text('30'),
                            ),
                            DropdownMenuItem(
                              value: '60',
                              child: Text('60'),
                            ),
                          ],
                        )
                      ],
                    )
                  : ListBody(
                      children: [
                        Text('time-step').tr(),
                        SizedBox(
                          height: 5.0,
                        ),
                        CupertinoSegmentedControl(
                          groupValue: timeStep,
                          children: {
                            '30': Text('30'),
                            '60': Text('60'),
                          },
                          onValueChanged: (value) {
                            setState(() {
                              timeStep = value;
                            });
                          },
                        ),
                      ],
                    ),
            ],
          ),
        ),
      );
    }
  }
  
  </code></pre>