Firebase Firestore Cloud Messaging And Storage and Notification Issues

Unhandled Exception: [core/not-initialized] Firebase has not been correctly

The above error might have two possible reasons.

1. Missing initialization at the top

This mostly happens if you are not initializing your Firebase before you MyApp() starts to run. To solive this you may need to do like this

void main() async {
  await init();
  runApp(const MyApp());

Future init() async {
  await Firebase.initializeApp();

2. Error in app/build.grade file

You build.gradle file should contain the below line

apply plugin: ''

And it's possible should be below other three

apply plugin: ''
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: ''

If you put the last line at the top you will get error.

Remote notifications are not supported in the simulator

If you get the above message for iOS simulator you need to sure that, you can not do notification on iOS simulator. You need to real device and an apple developer account.

flutter ios push notification for simulator

You see line 2

Now to really get notification you need to do something called FCM via APNs

Firebase message does not show up

When you test firebase message from firebase console, message doesn't show on your device. There might be many reasons. One of the reasons is, you are not sending token from the console.

But first you can get the token from your app. After you initialized firebase instances on your app, get the token using the below code

String? token = await FirebaseMessaging.instance.getToken();

Recent posts