close

[Solved] Error: A non-null value must be returned since the return type ‘Never’ doesn’t allow null

I am trying to use the firebase_messaging package in my flutter project But I am facing the following error Error: A non-null value must be returned since the return type ‘Never’ doesn’t allow null. We are going to Learn about All Possible Solutions So Lets Get Start with This Article.

How This Error Occurs ?

I am trying to use the firebase_messaging package in my flutter project But I am facing the following error.

Error: A non-null value must be returned since the return type ‘Never’ doesn’t allow null

How to solve this error. Let’s see all possible solutions to solve this error.

How To Solve Error: A non-null value must be returned since the return type ‘Never’ doesn’t allow null ?

  1. How To Solve Error: Method not found: ‘Error.throwWithStackTrace’?To Solve Error: Method not found: ‘Error.throwWithStackTrace’ Here By adding an override to these packages with older versions will solve this problem. So Just Open Your pubspeck.yaml file and add this firebase_messaging_platform_interface: 3.1.6 into your dependency_overrides. Here is my pubspeck.yaml file’s Example: dependency_overrides: firebase_messaging_platform_interface: 3.1.6 Now, your error must be solved.
  2. Error: Method not found: ‘Error.throwWithStackTrace’To Solve Error: Method not found: ‘Error.throwWithStackTrace’ Since Dart 2.16 they have added the throwWithStackTrace method So you just need to update your flutter to 2.10. And then your error must be solved. Just run this command in your terminal: flutter upgrade Now, Your flutter will be updated to the latest version of flutter and which is Flutter 2.10 as of now and now, your error must be solved.
  1. How To Solve Error: A non-null value must be returned since the return type ‘Never’ doesn’t allow null?

    To Solve Error: A non-null value must be returned since the return type ‘Never’ doesn’t allow null Since Dart 2.16 they have added the throwWithStackTrace method So you just need to update your flutter to 2.10. And then your error must be solved. Just run this command in your terminal: flutter upgrade Now, Your flutter will be updated to the latest version of flutter and which is Flutter 2.10 as of now and now, your error must be solved.

  2. Error: A non-null value must be returned since the return type ‘Never’ doesn’t allow null

    To Solve Error: A non-null value must be returned since the return type ‘Never’ doesn’t allow null By adding an override to these packages with older versions will solve this problem. So Just Open Your pubspeck.yaml file and add this firebase_messaging_platform_interface: 3.1.6 into your dependency_overrides. Here is my pubspeck.yaml file’s Example: dependency_overrides: firebase_messaging_platform_interface: 3.1.6 Now, your error must be solved.

Solution 1: Update Flutter to 2.10

Since Dart 2.16 they have added the throwWithStackTrace method So you just need to update your flutter to 2.10. And then your error must be solved. Just run this command in your terminal.

flutter upgrade

Now, Your flutter will be updated to the latest version of flutter and which is Flutter 2.10 as of now and now, your error must be solved.

Solution 2: Use dependency_overrides

Here By adding an override to these packages with older versions will solve this problem. So Just Open Your pubspeck.yaml file and add this firebase_messaging_platform_interface: 3.1.6 into your dependency_overrides. Here is my pubspeck.yaml file’s Example.

dependency_overrides:
  firebase_messaging_platform_interface: 3.1.6

Now, your error must be solved.

Solution 3: For all Firebase Service

If You are using multiple firebase services like firebase_messagingfirebase_crashlyticscloud_firestore and etc. Then Just add this all into your dependency_overrides of your pubspeck.yaml. Here is my example.

dependency_overrides:
  firebase_messaging_platform_interface: 3.1.6
  firebase_crashlytics_platform_interface: 3.1.13
  cloud_firestore_platform_interface: 5.4.13
  firebase_auth_platform_interface: 6.1.11
  firebase_storage_platform_interface: 4.0.14
  cloud_functions_platform_interface: 5.0.21
  firebase_analytics_platform_interface: 3.0.5
  firebase_remote_config_platform_interface: 1.0.5
  firebase_dynamic_links_platform_interface: 0.2.0+5
  firebase_performance_platform_interface: 0.1.0+5
  firebase_app_installations_platform_interface: 0.1.0+6

Now, Your error will be solved. Thank You. Still, None of any solutions worked for you Just comment below Your error We will be responding to Your Error.

Summary

It’s all About this error. Hope We solved Your error. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Leave a Comment