title: How to properly display a Snackbar in Flutter?
body: <p>I am trying to show a <code>Snackbar</code> on click of a <code>floatingActionbutton</code>. But when I click on the <code>floatingactionbutton</code> it's not showing anything. Here is my code. I am using a <code>StatefulWidget</code>. I debugged and checked that the onPressed function is also getting executed but somehow the <code>Snackbar</code> is not visible. What can be the root cause of the issue? I feel the BuildContext I am passing has some issue.</p>
  
  <pre><code>class MyApp extends StatefulWidget{
    @override
    MyAppState createState() {
      // TODO: implement createState
      return new MyAppState();
    }
  
  }
  
  class MyAppState extends State&lt;MyApp&gt;{
    File _image;
    String _text;
  
    Future getImage() async {
      var image = await ImagePicker.pickImage(source: ImageSource.camera);
      _image = image;
      final FirebaseVisionImage visionImage = FirebaseVisionImage.fromFile(_image);
      final TextRecognizer textRecognizer = FirebaseVision.instance.textRecognizer();
      final VisionText visionText = await textRecognizer.processImage(visionImage);
  
      String detectedText = visionText.text;
  
      setState(() {
        _image = image;
        _text = detectedText;
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        home: Scaffold(
          appBar: new AppBar(
            title: new Text('Image Picker Example'),
          ),
          body: new Center(
            child: _image == null
                ? new Text('No image selected.')
                : new Image.file(_image),
          ),
          floatingActionButton: new FloatingActionButton(
            onPressed: (){
              showSnackBar(context);
  //            getImage();
            },
            tooltip: 'Pick Image',
            child: new Icon(Icons.add_a_photo),
          ),
        ),
      );
    }
  
    void showSnackBar(BuildContext context) {
      final scaffold = Scaffold.of(context);
      final snackBarContent = SnackBar(
        content: Text("sagar"),
        action: SnackBarAction(
            label: 'UNDO', onPressed: scaffold.hideCurrentSnackBar),
      );
      scaffold.showSnackBar(snackBarContent);
    }
  
  }
  </code></pre>