Most users should use the Portal Flutter SDK directly. This guide is for advanced use cases requiring custom platform channel integration.
MethodChannel enables sending messages that correspond to method calls. On the platform side, MethodChannel on Android (MethodChannelAndroid) and FlutterMethodChannel on iOS (MethodChanneliOS) enable receiving method calls and sending back a result. These classes allow you to develop a platform plugin with very little ‘boilerplate’ code.
You can check the Flutter official documentation for platform channels.
You can check our Portal Flutter example.
Add Portal implementation for iOS:
- Open the iOS host portion of your Flutter app in Xcode.
- Add
PortalSwiftto the iOS project, you can follow this setup. - Open
AppDelegate.swiftlocated under Runner > Runner in the project navigation.
application:didFinishLaunchingWithOptions: function and create a FlutterMethodChannel
The client and host sides of a channel are connected through a channel name passed in the channel constructor. All channel names used in a single app must be unique; prefix the channel name with a unique ‘identifier’, for example: your.bundle.identifier/portal.
FlutterResult which expected to be passed from Flutter side as a completion handler.
Here is an example implementation:
PortalWrapper implementation:
Calling platform-specific code using platform channels
Now Portal iOS implementation is ready for Flutter, Let’s create the Flutter platform client: We will use the same channel name we defined above to initializeMethodChannel
String identifier initializePortal. The call might fail, so wrap the invokeMethod call in a try-catch statement.
initializePortal to initialize portal is ready to be called. You can call it from Flutter side passing the apiKey to initialize Portal.
And that’s it! You’re now equipped to integrate Portal into your Flutter app.