skip to Main Content
    /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/fluttertoast-8.1.3/lib/fluttertoast.dart:165:28: Error: Member not found: 'Overlay.maybeOf'.
    var _overlay = Overlay.maybeOf(context!);
                           ^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/fluttertoast-8.1.3/lib/fluttertoast.dart:154:18: Error: The getter 'mounted' isn't defined for the class 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart').
framework.dart:1
Try correcting the name to the name of an existing getter, or defining a getter or field named 'mounted'.
    if (context?.mounted != true) {
                 ^^^^^^^
3

FAILURE: Build failed with an exception.

* Where:
Script 'C:srcflutterpackagesflutter_toolsgradleflutter.gradle' line: 1159

After adding fluttertoast in my project it shows this problem while I run project on my device.
Now, what does it mean?

I was trying to show toast when an error or success occurred. But without snackbar fluttertoast is the only option to do.
But after adding dependency this problem showed.

4

Answers


  1. try to use this:

     if (!mounted) return;
     snackBar(yourText, context);//or use your fluttertoast
    
    

    if you had any problem or question i’m here to answer.

    happy coding.

    Login or Signup to reply.
  2. Update: Found the actual issue:

    Flutter toast v8.1.3 cannot work with a Flutter version older than 3.7.0 because of a breaking change in Flutter v3.7.0. You have to either use fluttertoast v8.1.2 or you have to upgrade your flutter version to v3.7.0+.

    Old Answer

    I faced a similar issue after running the flutter pub upgrade but even after rolling back the changes in the pubspec.yaml file, I got the same error. But this issue was fixed after rolling back the changes in the pubspec.lock file. Make sure to do flutter clean after reverting changes in pubspec.lock file.

    Login or Signup to reply.
  3. I also came across the same problem,
    Due to some limitations I was not able to change the flutter version, and Changing the version of fluttertoast has not led to any success. so what I do is try some other alternatives

    toast: ^0.3.0
    https://pub.dev/packages/toast
    

    I removed fluttertoast completely from the project and install a new dependency by running the command in the terminal

    flutter pub add toast
    

    usage:

    Toast.show("Toast plugin app", duration: Toast.lengthShort, gravity:  Toast.bottom);
    
    Login or Signup to reply.
  4. Unfortunately, this error is caused by a version incompatibility between the fluttertoast package and your version of Flutter. The Overlay.maybeOf method was removed in Flutter 2.0 and replaced with Overlay.of, which is likely what the fluttertoast package is using.

    In order to fix this error, you can try upgrading to the latest version of fluttertoast, or if that doesn’t work, downgrade your version of Flutter to a version compatible with the version of fluttertoast you are using.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search