title: How to dispose of flash bar in flutter when user disposes of screen?
body: <p>I am trying to find a way to dispose of flash bar (<a href="https://pub.dev/packages/flash" rel="nofollow noreferrer">flash package</a>) when <code>Navigator.of(context).pop()</code> is called. When user pops current screen where flash bar is visible it disappears only after its duration time has elapsed.</p>
  <p>I tried creating FlashController in screen that displays flash bar, and creating <code>FlashController</code> callback function from <code>showCustomFlashbar()</code> method where I would assign <code>FlashController</code> from <code>builder</code> to <code>FlashController</code> from screen it is used in.</p>
  <p>But let's say I want to use this flash bar in 50 different screens. That's too much copy/paste code each time. Is there a way it can be dismissed universally so that I wouldn't have to do that in every screen.</p>
  <p>My custom flash bar:</p>
  <pre><code>Future&lt;void&gt; showCustomFlashbar(BuildContext context,
      {required String message, Duration duration}) async {
  
    await showFlash(
        context: context,
        duration: const Duration(seconds: 5),
        transitionDuration: const Duration(milliseconds: 400),
        builder: (_, controller) {
          return CustomFlashbar(
            controller: controller,
            message: message,
          );
        });
  
    return;
  }
  
  class CustomFlashbar extends StatelessWidget {
    final FlashController controller;
    final String message;
  
    const CustomFlashbar(
        {Key? key, required this.controller, required this.message})
        : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return Flash(
        controller: controller,
        behavior: FlashBehavior.floating,
        position: FlashPosition.top,
        backgroundColor: Colors.red,
        child: FlashBar(
          content: Text(
            message,
          ),
        ),
      );
    }
  }
  </code></pre>
  <p>How it is used in code:</p>
  <pre><code>void showTestFlashbar() async {
    await showCustomFlashbar(context, 'This is test flashbar');
  }
  </code></pre>