【问题标题】:how can i add user defined variable in pubspec.yaml for flutter?如何在 pubspec.yaml 中添加用户定义的变量以进行颤振?
【发布时间】:2020-11-12 12:09:14
【问题描述】:

基本上我需要将版本和我的本地依赖项 URL 分配为用户定义的变量,并在路径中或我希望的任何地方分配相同的值

下面的例子

   mydependancyPath : D:\mylocalDependancy

   commonUtils:
   path:  mydependancyPath

1.请让我知道我怎样才能像上面那样实现

2.是否可以将另一个YAML文件导入pubspec.yaml

在Android中我可以实现如下

dagger_version=2.8

"com.google.dagger:dagger:${dagger_version}" 

【问题讨论】:

    标签: flutter dart yaml


    【解决方案1】:

    是否可以将另一个 YAML 文件导入 pubspec.yaml

    • 上面的答案是否定的,这是不可能的,因为pubspec.yaml 不支持导入。

    • 现在是您的主要问题: 例如,您可以使用YAML Anchors and Aliases:

      # this line has the path , and stored in varName for future use we use *varName
      mydependancyPath : &varNam D:\mylocalDependancy
      # this line has the version number , so we can use *vers as a key that holds the value 2.8
      myversion : &vers 2.8
      #!join is to concatinate 
      path : !join [*varName, *vers]
      

    here is a more detailed resource 因为我不确定语法,但这应该有助于您查找的内容

    【讨论】:

      猜你喜欢
      • 2022-11-04
      • 1970-01-01
      • 1970-01-01
      • 2020-09-24
      • 1970-01-01
      • 2018-11-06
      • 2020-07-19
      • 2021-01-26
      • 2021-06-29
      相关资源
      最近更新 更多