简体   繁体   中英

Flutter Compile Error on Firebase Auth: "A non-null value must be returned since the return type 'Never' doesn't allow null."

I'm using flutter fire and already did the console configuration, but everytime I try to run the code with an firebase_auth import I got this error.

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

The error message was added from dart 2.16 , ie from flutter 2.10, so the primary solution will be to upgrade your flutter version, which will also upgrade dart version.

So I ran into this problem recently while using firebase_storage

What I did to solve the problem was... (I was on flutter 2.5 and dart 2.14).

Upgrade flutter and dart version: Into terminal, run flutter upgrade or in my case, flutter upgrade --force , since flutter upgrade was giving me some issues. Then I added the latest version of the dependencies to my pubspec (firebase_storage_10.2.0) At this stage, running the app will likely throw an error about unsupported compileSDKVersion or so, and ask you to upgrade. For that, go into your app level build.gradle file

("project"\android\app\build.gradle),

and under android, change the compileSDKVersion from it's current value to what flutter asks you to change to. in my case, it was from 30 to 31

android{
       //change compile sdk version to 31 (in my case. flutter will tell you which version you should set to)
       compileSdkVersion 31
}

When you run the app now, it will check for licenses for the Android SDK Package you just edited (31). it should automatically accept and install everything neccessary. Flutter run might then fail again, with the error of an incompatible kotlin version, and that you should update or so. To update the kotlin version, go to the project level build.gradle ("project"/android/build.gradle) change the kotlin version here (ext.kotlin_version = '1.3.5') to the latest version which can be found Here . as of now, the latest version is 1.6.10 so this line of code now reads

ext.kotlin_version = '1.6.10'

Now you are good to go. run the app again, it might take much longer than usual, but it should work just fine. Or at least it worked fine for me.

I also had the same error. Try upgrading the dart version or use lower version of firebase_auth.

  firebase_auth: 2.0.0

firebase_auth: 2.0.0 worked for me.

Overall Complete Solution.

Solution:

Step 1:

The solution for this error is to upgrade to new flutter version.

Open Command Prompt and run this command.

flutter upgrade

Then after upgrading to new flutter version. Open your project and test it on your phone.

If shows error to upgrade kotlin version also, then: Step 2:

As we have upgrade to new version of flutter so we have to upgrader things also in build.gradle.

-> Go to android/build.gradle

-> change to ext.kotlin_version = '1.6.10'

For example,

In my old version i had ext.kotlin_version = '1.3.50' and now i change it to new ext.kotlin_version = '1.6.10' Please Check here the Example in Screenshot Image

Now Today Date is: 01/3/2022

In future: if you are reading this comment, then the version number ext.kotlin_version = '1.6.10' may be different.

So For latest new version number, go to this site:

https://kotlinlang.org/docs/gradle.html#plugin-and-versions

Here is the ScreenShot for Understanding

Step: 3

-> Go to android/app/build.gradle

-> change minSdkVersion to 19

-> add multiDexEnabled true

For example, Check here the example Screenshot

Now you can run and test the app on your phone. It will work 100 percent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM