Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Problem with adding Firebase Messaging

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.5.0, on Microsoft Windows [Versión 10.0.19042.1348], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc2)
[√] Chrome - develop for the web
[√] Android Studio (version 3.6)
[√] VS Code (version 1.52.1)
[√] Connected device (3 available)

My pubsec.yaml has only:
firebase_messaging: ^10.0.1
firebase_core: ^1.2.1
flutter_local_notifications: ^6.1.0

The problem I am having even on a brand new Flutter Project is that I am getting the following error when I add import 'package:firebase_messaging/firebase_messaging.dart'; to main.dart

/D:/Flutter/flutter_windows_2.5.0-stable/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_platform_interface-3.2.0/lib/src/method_channel/utils/exception.dart:13:11: Error: Method not found: 'Error.throwWithStackTrace'.
    Error.throwWithStackTrace(exception, stackTrace);
          ^^^^^^^^^^^^^^^^^^^
/D:/Flutter/flutter_windows_2.5.0-stable/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_platform_interface-3.2.0/lib/src/method_channel/utils/exception.dart:16:9: Error: Method not found: 'Error.throwWithStackTrace'.
  Error.throwWithStackTrace(
        ^^^^^^^^^^^^^^^^^^^
/D:/Flutter/flutter_windows_2.5.0-stable/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_platform_interface-3.2.0/lib/src/method_channel/utils/exception.dart:11:7: Error: A non-null value must be returned since the return type 'Never' doesn't allow null.
Never convertPlatformException(Object exception, StackTrace stackTrace) {
      ^


FAILURE: Build failed with an exception.

* Where:
Script 'D:\Flutter\flutter_windows_2.5.0-stable\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1005

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\Flutter\flutter_windows_2.5.0-stable\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 15s
Exception: Gradle task assembleDebug failed with exit code 1

like image 720
Carlos Castillo Avatar asked Mar 03 '26 21:03

Carlos Castillo


1 Answers

Error.throwWithStackTrace was added in Dart 2.16 (Flutter version 2.10 from Feb 8, 2022).

You should either:

  • Update Flutter to 2.10: flutter upgrade
  • Or use older version of conflicting package: firebase_messaging_platform_interface: 3.1.6
like image 95
Pavel Avatar answered Mar 06 '26 12:03

Pavel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!