[英]Error: A non-null value must be returned since the return type 'Never' doesn't allow null
[英]Flutter Compile Error on Firebase Auth: "A non-null value must be returned since the return type 'Never' doesn't allow null."
我正在使用 flutter fire 并且已经完成了控制台配置,但是每次我尝试使用 firebase_auth 导入运行代码时我都会收到此错误。
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.2.0/lib/src/method_channel/utils/exception.dart:12:7: Error: A non-null value must be returned since the return type 'Never' doesn't allow null.
错误消息是从dart 2.16添加的,即从flutter 2.10 添加的,因此主要解决方案是升级您的 flutter 版本,这也会升级 dart 版本。
所以我最近在使用firebase_storage时遇到了这个问题
我为解决问题所做的是......(我在 flutter 2.5 和 dart 2.14 上)。
升级 flutter 和 dart 版本:进入终端,运行flutter upgrade
或在我的情况下, flutter upgrade --force
,因为 flutter upgrade 给我带来了一些问题。 然后我将最新版本的依赖项添加到我的 pubspec (firebase_storage_10.2.0) 在此阶段,运行应用程序可能会抛出有关不受支持的 compileSDKVersion 左右的错误,并要求您升级。 为此,go 进入您的应用程序级别 build.gradle 文件
("项目"\android\app\build.gradle),
在 android 下,将 compileSDKVersion 从当前值更改为 flutter 要求您更改的值。 就我而言,它是从 30 到 31
android{
//change compile sdk version to 31 (in my case. flutter will tell you which version you should set to)
compileSdkVersion 31
}
当您现在运行该应用程序时,它将检查您刚刚编辑的 Android SDK Package 的许可证 (31)。 它应该自动接受并安装所有必要的东西。 Flutter 运行可能会再次失败,出现不兼容的错误 kotlin 版本,您应该更新左右。 要将 kotlin 版本 go 更新到项目级别 build.gradle ("project"/android/build.gradle) ,请将此处的 kotlin 版本(ext.kotlin_version = '1.3.5')更改为可在此处找到的最新版本。 截至目前,最新版本是 1.6.10 所以这行代码现在显示为
ext.kotlin_version = '1.6.10'
现在你可以拨打 go 了。再次运行该应用程序,它可能需要比平时更长的时间,但它应该可以正常工作。 或者至少对我来说效果很好。
我也有同样的错误。 尝试升级 dart 版本或使用较低版本的 firebase_auth。
firebase_auth: 2.0.0
firebase_auth:2.0.0 对我有用。
整体完整解决方案。
解决方案:
第1步:
此错误的解决方案是升级到新的 flutter 版本。
打开命令提示符并运行此命令。
flutter upgrade
然后升级到新的 flutter 版本后。 打开您的项目并在您的手机上进行测试。
如果升级kotlin版本也报错,则:第二步:
由于我们已经升级到 flutter 的新版本,所以我们也必须在 build.gradle 中升级一些东西。
-> Go 到 android/build.gradle
->更改为 ext.kotlin_version = '1.6.10'
例如,
在我的旧版本中,我有 ext.kotlin_version = '1.3.50' 现在我将其更改为新的 ext.kotlin_version = '1.6.10'请在此处检查屏幕截图中的示例
现在今天日期是:01/3/2022
将来:如果您正在阅读此评论,那么版本号 ext.kotlin_version = '1.6.10' 可能会有所不同。
所以对于最新的新版本号,go 到这个网站:
https://kotlinlang.org/docs/gradle.html#plugin-and-versions
步骤:3
-> Go 到 android/app/build.gradle
->将 minSdkVersion 更改为 19
->添加 multiDexEnabled true
例如,在此处检查示例屏幕截图
现在您可以在手机上运行和测试该应用程序。 它将 100% 发挥作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.