Reputation: 1
Event channel not workinng in IOS. onlisten method not getting called. Method channel is working fine in IOS. Only issue is with event channel.
In android event channel and method channel working fine.
Has anyone else dealt with this? Any tips or solutions would be really appreciated! Thanks
IOS code
import Flutter
import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let eventChannel = FlutterEventChannel(name:"hello_connection/event_channel", binaryMessenger:controller.binaryMessenger)
eventChannel.setStreamHandler(Hello())
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
import Flutter
import UIKit
class Hello: NSObject, FlutterStreamHandler {
var eventSink: FlutterEventSink?
func onListen(withArguments arguments: Any?, eventSink: @escaping FlutterEventSink) -> FlutterError? {
self.eventSink = eventSink
self.eventSink?("hello")
return nil
}
func onCancel(withArguments arguments: Any?) -> FlutterError? {
eventSink = nil
return nil
}
}
Flutter code
class ExampleWorld extends StatelessWidget {
ExampleWorld({super.key});
static const eventChannel = EventChannel('hello_connection/event_channel');
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: SafeArea(
child: SizedBox(
width: double.maxFinite,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
eventChannel.receiveBroadcastStream().map(
(map) => print("event channel"),
);
},
child: Text('start event channel'),
),
],
),
),
),
);
}
}
Tried with github and stackoverflow
Upvotes: 0
Views: 93