1

Recently I've developed a native ios library using Swift 5.

This library is being distributed using Cocoapods and now that is done I would like to know if there's any method to use that same library in a Flutter application from Cocoapods and which is the best way to do it.

What I've tried so far:

I tried creating a flutter demo app and moving to /ios for running pod init and later configuring my Podfile to point the source of the Pod and after that I did a pod install. Apparently this works, because if I go to my Runner.xcworkspace and add import MyLib to the AppDelegate, it compiles.

The thing is, how do I access the methods and classes of the Pod from my Dart code? Is it possible or I have to manage that interaction directly from Swift?

Thank you very much.

3
  • 3
    You can execute native code via method channel. Check this link - docs.flutter.dev/development/platform-integration/… Commented Mar 28, 2022 at 16:27
  • Thank you very much, Anyway I would like to know if there's a simpler way, because the library I need to use is a little big, so if I use the channels method it might take too much time. Commented Mar 31, 2022 at 2:45
  • 1
    Hi, does my answer solve your question? Commented Apr 5, 2022 at 0:25

1 Answer 1

2
+50

Yes and no. You need to manually write down some boilerplate between Swift and Dart. But this can be simplified by some code generators, for example pigeon.

If you are using other languages like Rust instead of Swift, there does exist more advanced code generators that requires almost zero boilerplate. But there seems none for Swift.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.