Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build failed: the getter 'mounted' isn't defined for the class 'BuildContext'

Tags:

flutter

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.

like image 247
SaDev Avatar asked Sep 06 '25 03:09

SaDev


1 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.

like image 148
SaDev Avatar answered Sep 08 '25 00:09

SaDev