dart Fluttertoast问题:未找到成员:'覆盖.可能是'

30byixjq  于 2023-02-10  发布在  Flutter
关注(0)|答案(2)|浏览(286)
/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:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1159

在我的项目中添加fluttertoast后,当我在设备上运行项目时,它显示了这个问题。现在,它意味着什么?
我试图显示吐司时,一个错误或成功发生。但没有snackbar fluttertoast是唯一的选择这样做。但添加依赖关系后,这个问题显示。

gr8qqesn

gr8qqesn1#

    • 更新:发现实际问题:**

Flutter toast v8.1.3无法与3.7.0之前的Flutter版本一起工作,因为Flutter v3.7.0中存在breaking change。您必须使用fluttertoast v8.1.2,或者必须将flutter版本升级到v3.7.0+。

    • 旧答案**

我在运行flutter pub upgrade后遇到了类似的问题,但即使在回滚pubspec.yaml文件中的更改后,我也得到了相同的错误。但在回滚pubspec.lock文件中的更改后,这个问题得到了修复。请确保在还原pubspec.lock文件中的更改后执行flutter clean

bvhaajcl

bvhaajcl2#

试着用这个:

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

如果你有任何问题我都可以回答
快乐的编码。

相关问题