I am using snackbar to display the toast in my flutter app. Now, when I am running the app, I am a build failed error:
The getter ‘mounted’ isn’t defined for the class ‘BuildContext’.
../…/lib/fluttertoast.dart:155
- ‘BuildContext’ is from ‘package:flutter/src/widgets/framework.dart’ (‘../../Downloads/flutter/packages/flutter/lib/src/widgets/framework.dart’).
package:flutter/…/widgets/framework.dart:1
Try correcting the name to the name of an existing getter, or defining a getter or field named ‘mounted’.
I do not get why because I am not using fluttertoast plugin anywhere in my application.
Please see my code below:
void _showSnackBar(String message) {
final snackBar = SnackBar(
content: Text(message),
backgroundColor: SSColours.primary,
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
May you please help, thanks.
2
Answers
I found my solution. After doing much investigation, I found out there was nothing wrong with my code, I just needed to upgrade my flutter to the latest version.
You can pass the
BuildContext
on the method