0

I'm working on a Flutter app with some native kotlin code. It's straightforward to call native methods from Flutter through the MethodChannel, and vice-versa (from MainActivity).

However, I also want a way to trigger Flutter code triggered from a native Broadcast receiver, where I don't have the original MethodChannel. The problem is, I'm not sure how to create a FlutterEngine with the right arguments to get access to the same MethodChannel.

Is there a way to construct the same FlutterEngine that can be used to call back into Flutter code? What I want to do:

var flutterEngine = FlutterEngine(XXX)
var flutterChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, FLUTTER_CHANNEL)
flutterChannel.invokeMethod(...)

I'm not sure what XXX should be here to get the same Channel I have in MainActivity. If there's some info I need to pass from MainActivity, I could use intents to pass it to my broadcast receiver, but it's not clear what is needed.

xcoder
  • 1

1 Answers1

0

Flutter Engine and Channels work with named scopes, if you uses the same engine name end channel is the same channel in Flutter side.

  • Thanks, I got the engine / channel names (engine is created by flutter, but I printed out the name), but engine / channel don't seem to have a constructor that takes a name. Channel needs a binaryMessenger, which is a property of the engine, and I'm not sure how to construct the engine with just a name. – xcoder Mar 18 '20 at 00:28
  • @xcoder did you find solution to this issue? – Shruthi Dec 01 '22 at 14:57