1

Hello there I am new to programming. I'm building an app in flutter, but I have some issue with snackbar. I'm building an image with a wrapped button and an onPressed method with a print statement that work. I want to put inside the onPressed method a snackbar to show a message. I've done the following code:

        onPressed: () {
          Scaffold.of(context).showSnackBar(SnackBar(
            content: Text('Show Snackbar'),
            duration: Duration(seconds: 3),
          ));
          print('Image pressed.');
        },

My button work. But no snackbar show and android studio run the following error:

Compiler message:

lib/main.dart:20:27: Error: Getter not found: 'context'.
              Scaffold.of(context).showSnackBar(SnackBar(
                          ^^^^^^^

What i have to do, for showing a toast/snackbar once pressed my image?

Omkar
  • 3,253
  • 3
  • 20
  • 36
Simone
  • 11
  • 2

0 Answers0