title: Why sometimes snackbar is failing
body: <p>Please help to explain why sometimes my SnackBar is showing an error. I don't understand at which circumstance the issue will come. I just want to point also that even though it is showing the error, in the app itself, it is working fine.</p>
  <p>Here's my code:</p>
  <pre><code>void showFailedSnackBar(String s) {
      SnackBar snackBar = SnackBar(
        content: Text(s),
        duration: Duration(seconds: 3),
        backgroundColor: Theme.of(context).primaryColor,
      );
  
      ScaffoldMessenger.of(context).showSnackBar(snackBar);
    }
  </code></pre>
  <p>Here's the error:</p>
  <pre><code>E/flutter ( 7879): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: This widget has been unmounted, so the State no longer has a context (and should be considered defunct).
  E/flutter ( 7879): Consider canceling any active work during &quot;dispose&quot; or using the &quot;mounted&quot; getter to determine if the State is still active.
  </code></pre>