【问题标题】:Flutter: Add plugin only for iOS in pubspec.yaml fileFlutter:在 pubspec.yaml 文件中添加仅适用于 iOS 的插件
【发布时间】:2019-09-04 02:54:50
【问题描述】:

有没有办法在pubspec.yaml 文件中为特定平台(例如仅适用于 iOS)添加插件?

类似的东西。

dependencies:
  flutter:
    sdk: flutter

  isIos ? http: ^1.0 : null

PS:我也知道我可以正常导入插件并且在代码中,我可以进行更改,但我不想要这个解决方案。

if (Theme.of(context).platform != TargetPlatform.iOS) {
  // don't use that plugin part
}

我只是不想在我的pubspec.yaml 中为特定平台添加插件。可能吗?

【问题讨论】:

标签: dart flutter


【解决方案1】:

无法仅为特定平台添加插件。不过,有一种更简单的方法可以访问当前平台。

import 'dart:io';


if(Platform.isIOS) {
 // Use plugin
}
 

【讨论】:

    【解决方案2】:

    使用

    Platform.isIOS

    import 'dart:io' show Platform;
    
    if (Platform.isAndroid) {
      // Android-specific code
    } else if (Platform.isIOS) {
      // iOS-specific code
    }
    

    【讨论】:

      【解决方案3】:

      不确定,但一种可能的方法是本地安装该 pod 并在 Xcode 中编写其实现,然后通过 Flutter 应用程序调用该本地代码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-10-13
        • 2019-12-04
        • 2019-05-13
        • 2021-05-03
        • 1970-01-01
        • 2019-01-20
        • 1970-01-01
        相关资源
        最近更新 更多