Skip to main content
Most users should use the Portal Flutter SDK directly. This guide is for advanced use cases requiring custom platform channel integration.
In order to integrate Portal into your Flutter App using native platform channels, you will need to write custom platform-specific code. On the client side, 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:

  1. Open the iOS host portion of your Flutter app in Xcode.
  2. Add PortalSwift to the iOS project, you can follow this setup.
  3. Open AppDelegate.swift located under Runner > Runner in the project navigation.
Override the 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.
Then define a callback to handle any method invocation that comes from the Flutter side and they Switch on those Methods then execute the proper Swift implementation for each one and reply back to Flutter using a regular callback of type FlutterResult which expected to be passed from Flutter side as a completion handler.

Here is an example implementation:

And here is an 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 initialize MethodChannel
Next, invoke a method on the method channel, specifying the concrete method to call using the String identifier initializePortal. The call might fail, so wrap the invokeMethod call in a try-catch statement.
Finally, your Flutter function 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.