Add Pod dependency to a Flutter Plugin Class
Asked Answered
G

1

6

Finally I got a custom Flutter Plugin's MethodChannel to do the hello-world.

But now, I would like to add a dependency explicitly to the iOS part of the Plugin Class (obviously not to the Android-part...).

However, this somehow bites the snake in its tale since the Plugin Class is itself part of the Flutter Pod. So how does this work ?

I added the following inside the /iOS/Podfile

target 'Runner' do
  use_frameworks!

  pod `MyPodDependency`

The code compiles.

But the import MyPodDependency fails. (inside my Plugin Class where I also program the public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {...} code, to be found under ../Pod/../../../../ios/Classes/MyPluginClass.swift)

My question: How do I import MyPodDependency inside the iOS part of the Flutter Plugin-Class?

In which of the Podfiles do I need to add my pod.

Can I use any imported Framework inside the Plugin Class (where the FlutterMethodCall's handle method sits)? And if yes, how ???

Gastrotomy answered 10/1, 2019 at 21:50 Comment(1)
I am facing the same issue while trying to use my local .framework in flutter plugin. Did you find a solution?Woodrum
S
7

You have to remember that a plugin must work in any project, not only in yours. This is why its dependencies shouldn't be inside your project's pod file, but contained in its own dependencies file, otherwise, everyone would always have to add manually each dependency of all the plugins used in a project.

That said, your plugin dependencies must be referenced inside the .podspec file, located in the /ios directory of your plugin. This will execute when you run "pod install" in your project, fetching all external dependencies your plugin needs. If you take a look in the existing file, it already presents one dependency:

s.dependency 'Flutter'

Follow the example and add your other plugin dependencies below.

Finally, you will have to add the plugin to your Flutter project. Simply add it to the pubspec file, as you would do with all other plugins.

Sculpturesque answered 6/8, 2019 at 18:10 Comment(1)
And how can I add a dependency from git? I need to add pod 'SDK-iOS', :git => "https://github.com/cloudpayments/SDK-iOS", :branch => "master" to my plugin. But it seems like .podspec file doesn't allow me to do it.Snub

© 2022 - 2024 — McMap. All rights reserved.