I have a flutter application where I have written kotlin code and I have set up method channel to communicate. There is a method in kotlin code which is invoked periodically by alarmManager. I want this method to call another method written on the dart side. How can I make this happen?
Asked
Active
Viewed 632 times
0
-
most likely you need https://api.flutter.dev/flutter/services/EventChannel-class.html – pskink Oct 03 '22 at 11:05
-
I don't think Event Channel can be used for 2 way communication – Pro Oct 03 '22 at 11:06
-
it can, you put events into the channel on kotlin side and listen to those events on dart side, call any function you want in the stream.listen lambda https://api.flutter.dev/flutter/dart-async/Stream/listen.html – eeqk Oct 03 '22 at 11:37
-
See: https://stackoverflow.com/questions/50187680/how-to-call-methods-in-dart-portion-of-the-app-from-the-native-platform-using-m/50188557#50188557 – Richard Heap Oct 03 '22 at 14:27
1 Answers
1
MethodChannel works in both directions.
Create another channel for methods dart provides. Call setMethodCallHandler to handle incoming methods in dart and then call invokeMethod from Android invoke one.

user18309290
- 5,777
- 2
- 4
- 22
-
There's no need to create another channel; you can use the normal Dart->native channel bidirectionally. – Richard Heap Oct 03 '22 at 14:30
-
How will I use the invokeMethod from a different Activity which is triggered by the alarmManager? – Pro Oct 03 '22 at 17:04
-