首页 > 解决方案 > 如何在 pubspec.yaml 中添加用户定义的变量以进行颤振?

问题描述

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

像下面这样的例子

   mydependancyPath : D:\mylocalDependancy

   commonUtils:
   path:  mydependancyPath

1.请让我知道如何实现上述目标

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

在Android中我可以实现如下

dagger_version=2.8

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

标签: flutterdartyaml

解决方案


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

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

  • 现在对于您的主要问题:您可以使用YAML Anchors 和 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]
    

这是一个更详细的资源,因为我不确定语法,但这应该有助于您寻找什么


推荐阅读