終端創(chuàng)建 flutter 插件:
com.example: 項目的 bundle ID / 包名
xxx_plugin:插件名稱
flutter create --org com.example --template=plugin --platforms=android,ios -i swift -a kotlin xxx_plugin
顯示的目錄:

插件目錄.png
iOS 篇

iOS 插件目錄.png
Assets:存放資源
Classes:存放 swift / OC 代碼
sound_plugin.podspec:配置依賴某些庫
以我項目為例子,項目里依賴了本地庫 xxx.framework:
① 創(chuàng)建一個 Frameworks 文件夾 將本地依賴庫添加進(jìn)去

Frameworks.png
② 配置 .podspec 文件:
Pod::Spec.new do |s|
s.name = 'sound_plugin'
s.version = '0.0.1'
s.summary = 'A Sound Flutter plugin.'
s.description = <<-DESC
A Sound Flutter plugin.
DESC
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' }
s.author = { 'Your Company' => 'email@example.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.platform = :ios, '9.0'
s.vendored_frameworks = 'Frameworks/xxx.framework' #依賴xxx庫(本地庫路徑)
s.frameworks = 'xxx' #依賴xxx庫,會添加到插件項目 Frameworks and Libraries中
# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
s.swift_version = '5.0'
end
③ 把寫好的原生交互代碼全部拖進(jìn) Classes 中
④ 打開 flutter 創(chuàng)建的插件項目中得 example

iOS.png
進(jìn)行 pod install 操作
當(dāng)遇到無法識別 xxx.framework 時,可在

image.png
如果iOS原生項目能運行起來就說明成功了!