Notification is not coming in release mode when flutter app is in background
Asked Answered
E

1

6
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await GetStorage.init();
  await Firebase.initializeApp();
  await PushNotificationsService().init();
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  runApp(MyApp());
  setuplocator();
}

Above code is set on main thread. Now the problems is that app not received notification when it is on background. on foreground it works fine. But it is not working in background.

But this all is happening in debug mode and not in release mode. What to do ?

Erstwhile answered 28/11, 2022 at 11:16 Comment(0)
E
28
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// handle message
}

Just add @pragma('vm:entry-point') on above _firebaseMessagingBackgroundHandler method

I have to note again that this issue only occurs on release builds and only on Android platforms (I have tested this in an emulator with Android 13, as well as a Samsung device running Android 12). In debug and profile mode, the app receives 2 notifications, one from the native Firebase Messaging, and one from the Flutter background handler's firebase_local_notifications, and it should do it in release mode too (this works correctly in 3.0.5), but instead, in 3.3.0 all it shows is the native notification, no trace of the flutter_local_notifications generated one.

Erstwhile answered 30/11, 2022 at 5:46 Comment(1)
This should be on the documentation. Thanks for the solutionMendoza

© 2022 - 2024 — McMap. All rights reserved.