Debug School

rakesh kumar
rakesh kumar

Posted on

Flutter Error:try conneting name to existing method defining showSnackBar in fluttr

showsnackbar-is-deprecated-and-shouldnt-be-used

Error:
'showSnackBar' is deprecated and shouldn't be used

Old Method (using scaffold key):

_scaffoldkey.currentState.showSnackBar(snackbar);

Solution:
This is the new way to add snackBars to the scaffold.

ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text("Incremented"), duration: Duration(milliseconds: 300), ), );
Enter fullscreen mode Exit fullscreen mode

==============OR======================================

 ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text(message), duration: Duration(milliseconds: 300), ), );
Enter fullscreen mode Exit fullscreen mode
Using _key.currentState.ShowSnackBar(snackbar) Is deprecated now.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)