Home > Back-end >  Flutter Compile Error on Firebase Auth: "A non-null value must be returned since the return typ
Flutter Compile Error on Firebase Auth: "A non-null value must be returned since the return typ

Time:02-27

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.

CodePudding user response:

The error message was added from dart 2.16, i.e 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.

CodePudding user response:

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.

  • Related