插件可以通過向pubspec.yaml
中的platforms
map 添加keys 來指定其支援的平台
例如,以下是hello
插件的flutter:
map:
hello
插件僅支援 iOS 和 Android,在platforms
map 添加keys,指定其支援的平台
flutter:
plugin:
platforms:
android:
package: com.example.hello
pluginClass: HelloPlugin
ios:
pluginClass: HelloPlugin
environment:
sdk: ">=2.1.0 <3.0.0"
# Flutter versions prior to 1.12 did not support the
# flutter.plugin.platforms map.
flutter: ">=1.12.0"
當為更多平台添加插件實現時,應相應地更新platforms
map
flutter:
plugin:
platforms:
android:
package: com.example.hello
pluginClass: HelloPlugin
ios:
pluginClass: HelloPlugin
macos:
pluginClass: HelloPlugin
web:
pluginClass: HelloPlugin
fileName: hello_web.dart
environment:
sdk: ">=2.1.0 <3.0.0"
# Flutter versions prior to 1.12 did not support the
# flutter.plugin.platforms map.
flutter: ">=1.12.0"