-1

I am revisiting an old code and it is giving me this error and I am not sure how to fix it..

 void _showSuccessSnack() {
    final snackbar = SnackBar(
      content: Text(
        'User $_username successfully created!',
        style: new TextStyle(color: Colors.greenAccent),
      ),
    );
    _scaffoldKey.currentState!.showSnackBar(snackbar);
    _formKey.currentState!.reset();
  } 
_scaffoldKey.currentState!.showSnackBar(snackbar); -The method 'showSnackBar' isn't defined for the the type 'ScaffoldState'

I am not sure what's the best strategy here to follow.. erase line.. replace it with something else?

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
acnow
  • 1

1 Answers1

0

Try this :

void _showSuccessSnack() { 
final snackbar = SnackBar( content: Text( 'User $_username successfully created!', style: new TextStyle(color: Colors.greenAccent), ), );
ScaffoldMessenger.of(context).showSnackBar(snackbar);
_formKey.currentState!.reset();
}