I have created a Common class for SnackBar,
class MySnackBar extends StatelessWidget {
String message;
int duration;
BuildContext context;
MySnackBar(BuildContext context,String message, int duration) {
this.message = message;
this.duration = duration;
this.context = context;
}
@override
Widget build(BuildContext context) {
return _showSnackBar(this.context, message, duration);
}
Widget _showSnackBar(BuildContext context, String message, int duration) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(message),
duration: Duration(seconds: duration),
));
}
}
I am calling this class from my other widget like this,
MySnackBar(
context,
_postDetailsModel
.language.postScreen.bookmarkOwnMessage,
3);
But it neither displays snackbar nor it throws an error. Can anyone tell me what I am missing or is there is a way to create common snackbar class?