Wednesday 3 May 2023

FlutterFragment with FlutterPlugin - how to get a reference

I'm currently using a FlutterFragment inside an AppCompatActivity.

Also, I'm using a pre-warmed up flutter engine and a FlutterPlugin to have a methodChannel from and to native/flutter when needed.

I am currently in a situation where I want to start a specific method to flutter via the plugin when my FlutterFragment is loaded.

I know right now that onAttachedToEngine is called in the FlutterPlugin when the plugin is attached to Engine.

But now the FlutterFragment needs to call the plugin when it starts.

How can I make sure the plugin is attached to the engine before the FlutterFragment invokes the plugin call. And the other way around, how can I make sure the FlutterFragment is attached and ready before the plugin calls anything on the fragment.

The only thing I have seen is the ActivityAware interface. I thought of getting the fragment from the fragmentManager from the activity, but these interface methods are never called for some reason.

Side-note: I can't change the AppCompatActivity to a FlutterFragmentActivity that easily, so if it's not needed, then that has my preference.



from FlutterFragment with FlutterPlugin - how to get a reference

No comments:

Post a Comment