iT邦幫忙

2021 iThome 鐵人賽

DAY 4
0
Mobile Development

Flutter - 從 Packages & Plugins 掌握原生系列 第 4

Day04 指定插件所支援的平台

指定插件所支援的平台

插件可以通過向pubspec.yaml中的platformsmap 添加keys 來指定其支援的平台

例如,以下是hello插件的flutter:map:

hello插件僅支援 iOS 和 Android,在platformsmap 添加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"

當為更多平台添加插件實現時,應相應地更新platformsmap

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"

上一篇
Day03 Federated plugins (聯合插件)
下一篇
Day05 platform channels
系列文
Flutter - 從 Packages & Plugins 掌握原生30

尚未有邦友留言

立即登入留言