dart - pubspec.yaml 中的配置标志如何工作?

我正在学习 Flutter 和 Dart。我注意到pubspec.yaml 文件似乎不仅仅包含第三方库的依赖版本。例如。

# The following section is specific to Flutter.
flutter:
  uses-material-design: true

我了解 Dart Pub Tool定义了 pubspec.yaml 的格式,看起来像 Flutter 这样的框架可以通过额外的设置来增强 pubspec.yaml,从而引发以下问题:

  • pubspec.yaml 是设计用于提供配置标志还是仅用于提供依赖项?
  • flutter 的方式是使用 pubspec.yaml 惯用的 Dart 还是唯一的?
  • pubspec.yaml 是仅由 pub 工具解析还是在运行时作为通用应用程序配置文件解析?
  • Flutter 是否为 pubspec.yaml 实现了自己的解析器,并使 uses-material-design: true 等设置在运行时可用?

最佳答案

Is pubspec.yaml designed to be used to provide configuration flags or only dependencies?

从历史上看,它还包含纯 Dart 项目中的build设置。例如用于编译为 JS 的设置,但已移出到 build.yaml。见 https://github.com/dart-lang/build/blob/master/build_config/README.md

Does the way flutter use pubspec.yaml idiomatic Dart or unique?

这是 Flutter 独有的。

Does Flutter implement it's own parser for pubspec.yaml and make settings like uses-material-design: true available at runtime?

是的。

这些设置是构建时设置,而不是运行时设置。


其实我觉得这个文件混淆了不同的用途是相当不幸的。在 Flutter 早期,特定于 Flutter 的设置在不同的文件中,但这也造成了一些困难(不知道细节 - 只在 GitHub 讨论中看到它)所以他们将它与 pubspec.yaml 合并>.

https://stackoverflow.com/questions/55768557/

相关文章:

dart - 在 RichText 小部件中向 TextSpan 背景添加额外的填充

dart - 桶填充 flutter

flutter - 在 AWS Device Farm、Saucelabs、Firebase 测试实

visual-studio - 是否可以在 Visual Studio 2017 IDE 上设置 f

android - 库 com.google.android.gms :play-services-

dart - Flutter:如何正确实现 FlutterError.OnError

flutter - 如何使用 FlutterDriver 检查小部件是否可见

flutter - 如何从 TextField 中删除内容填充?

android - Flutter 检索 ro.product.cpu.abi 的设备属性时出错

text - 如何使用 Flutter 编写带有要点的段落?