Unhandled Exception: [core/not-initialized] Firebase has not been correctly
The above error might have two possible reasons.
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 {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
}
You build.gradle file should contain the below line
apply plugin: 'com.google.gms.google-services'
And it's possible should be below other three
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
If you put the last line at the top you will get error.
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.
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();
print(token!)