1

Always getting this error on a project without any reason for the moment could you help me on this.

Undefined name 'ScaffoldMessenger'. Try correcting the name to one that is defined, or defining the name.

Flutter version : 1.22.5 stable

Could you help me on this please ?

Moez Zineb
  • 15
  • 2
  • 7

4 Answers4

3

Got the same error and I tried this and it work

       ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
             content: Text('Some Text'),
                  ),
                 );
Godwin
  • 608
  • 1
  • 9
  • 14
2

If you are still experiencing this issue you might have to update your Flutter sdk.

ScaffoldMessenger was first released to Flutter stable channel the 3th of March 2021...

To update flutter just run

flutter upgrade

on your terminal/command line.

For further details take a look at the ScaffoldMessenger documentation or in StackOverflow see this thread.

deczaloth
  • 7,094
  • 4
  • 24
  • 59
1

According to https://flutter.dev/docs/release/breaking-changes (at the moment), under Not yet released to stable, we see SnackBars managed by the ScaffoldMessenger. So, it's not in 1.22... it'll be in the next release.

Randal Schwartz
  • 39,428
  • 4
  • 43
  • 70
0

If you get an error that scaffold is not present then, use builder widget to get the context and then use the scaffold.of() part.

Tanmoy Karmakar
  • 192
  • 1
  • 4