I'm trying to call Facebook app events in my flutter project. I'm using the dependency facebook_app_events: ^0.12.0. meta-data is also added in the manifest file.
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
void callFBEvent() async {
try {
var i = await facebookAppEvents.getAnonymousId();
await facebookAppEvents.setAdvertiserTracking(enabled: true);
await facebookAppEvents.logEvent(
name: "User_Selection_Screen", parameters: {
"User_Selection": "User_Selection",
});
print("facebook event success User_Selection_Screen");
}catch(e){
print(e);
}
}
Getting below error
kotlin.UninitializedPropertyAccessException: lateinit property anonymousId has not been initialized
at id.oddbit.flutter.facebook_app_events.FacebookAppEventsPlugin.handleGetAnonymousId(FacebookAppEventsPlugin.kt:82)
at id.oddbit.flutter.facebook_app_events.FacebookAppEventsPlugin.onMethodCall(FacebookAppEventsPlugin.kt:55)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:822)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:336)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:7386)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
I open the project in an android module. Then just clean the build of the project first and then just build and sync the Gradle in the android module. then the issue was solved. But I already use pub get lots of time before that but that didn't work. fine, my issue was solved.