47

Suddenly this error appears in the debug console. I do not know what I did wrong.

Error image

My Car
  • 4,198
  • 5
  • 17
  • 50
MsPoojitha
  • 473
  • 1
  • 3
  • 6

9 Answers9

52

You've upgraded Flutter but not the packages. In the terminal enter

flutter pub outdated

Then upgrade the outdated packages one by one like this:

flutter pub upgrade outdated_package

After you're finished:

flutter clean

and

flutter pub get

Your problem should now be solved.

Ariel H.
  • 698
  • 7
  • 11
5

I had the same issue and stumped on this post.

In my case I was able to detect which plugin was in fact giving the error and it turned out to be firebase_core. So, I decided to upgrade the package to the latest version which happened to be 1.21.1 in my case.

So, to solve the issue I will suggest you try changing the version of the firebase_core package you're using to the latest in the pubspec.yaml file of your project like so:

firebase_core: ^1.21.1 (replace with latest verison)

Or you can just run:

flutter pub upgrade firebase_core

This will upgrade firebase_core to the latest version.

Or you can as well put any as the version code in the pubspec.yaml file of your project like so:

firebase_core: any (upgrades firebase_core to the latest verison)
John Oyekanmi
  • 342
  • 1
  • 7
5

I spent a long time looking into this and eventually traced it to the plugin registrar being nil when setting up the plugin.

This was caused by setting my iOS app root view controller to anything other than FlutterViewController (i.e. in my case, I had a UINavigationController as the root). This will result in a failure to register all your plugins.

The app delegate assumes that the root view controller is a FlutterViewController, so if it isn't then you will need to re-direct all plugin-related function calls to your FlutterViewController from your app delegate by overriding these functions as follows:

    override func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar? {
        flutterViewController.registrar(forPlugin: pluginKey)
    }

    override func hasPlugin(_ pluginKey: String) -> Bool {
        flutterViewController.hasPlugin(pluginKey)
    }

    override func valuePublished(byPlugin pluginKey: String) -> NSObject? {
        flutterViewController.valuePublished(byPlugin: pluginKey)
    }
Jonathan Ellis
  • 5,221
  • 2
  • 36
  • 53
  • 2
    This answer really needs more upvotes. The error happens exactly because of this. Sometimes the plugin registrar files are just out of date (or missing) and the commands in other answers fix them, but in some cases you might setup `FlutterViewController` wrong - especially in case of not having FlutterAppDelegate. So this answer gives you the correct direction. Helped me out a lot @jonathan, thanks! – Legoless Mar 17 '23 at 12:25
  • 1
    Thank you for looking into the root cause. I then solve the problem by adding `GeneratedPluginRegistrant.register(with: ...` as the documentation said. (I was using the codes in *Create a FlutterViewController with an implicit FlutterEngine* section of the document so I somehow missed that PluginRegistrant thing.) – autodavid May 02 '23 at 03:33
  • Oh and by the way, if your `FlutterViewController` is inside a `UINavigationController`, you'll also find that `SystemChrome.setPreferredOrientations()` won't work either. I've just posted a workaround to that problem [here](https://stackoverflow.com/a/76191411/555485) (posting here as I reckon people will be looking at this answer who are likely to run into this issue!) – Jonathan Ellis May 06 '23 at 22:22
1

If you are using these dependecies then replace it with a latest version:

  • firebase_messaging
  • firebase_core
  • flutter_local_notifications

Then in android/app/build.gradle update compileSdkVersion flutter.compileSdkVersion to 33

Paul
  • 1,344
  • 4
  • 19
  • 37
0

Please also check the compileSdkVersion in android/app/build.gradle and update it to 33

0

I was have this problem. after downgrade awesome_notifications package to 0.6.21, resolved this.

Ali Bagheri
  • 3,068
  • 27
  • 28
0

I also effected from that issue for few hours, finally I found issue that was I ran my emulator as windows (:, yeah please run with Android emulator you selected vm.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 27 '23 at 03:17
0

In my case i was trying to use "google_mobile_ads" and "admob_flutter" at the same time. You must choose one only.

Xavier Soh
  • 47
  • 5
-2

This exception could also be thrown if you are running your app on windows, Try to run it on emulator.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 01 '23 at 05:59