flutter - 我如何在 pubspec.yaml 中添加用户定义的变量以进行 flutter ?

标签 flutter dart yaml

基本上我需要将版本和我的本地依赖项 URL 分配为用户定义的变量,并在路径或我希望的任何地方分配相同的内容
像下面这样的例子

   mydependancyPath : D:\mylocalDependancy

   commonUtils:
   path:  mydependancyPath

1.Please let me know how can I achieve as like above

2.Is it possible to import another YAML file into pubspec.yaml


在Android中我可以实现如下
dagger_version=2.8

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

最佳答案

Is it possible to import another YAML file into 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因为我不确定语法,但这应该对您要查找的内容有所帮助

    关于flutter - 我如何在 pubspec.yaml 中添加用户定义的变量以进行 flutter ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64803659/

    相关文章:

    android - 在BottomNavigationBar上调用选定索引的小部件的initState

    flutter - 如何使用 flutter 在 FL Chart 内部绘制标记

    iOS 应用程序在真实设备上崩溃。错误 : dyld`__abort_with_payload

    java - 来自配置 yaml 的绑定(bind)映射

    node.js - 如何安装新的 nodejs 模块到 expressjs 项目?

    php - 用 PHP 解析 YAML 前端内容

    flutter - 动画切换器和 Bloc Builder

    flutter - 无法在 Macbook air M1 中安装 cocoapods,每次创建 flutter 项目时 pod 文件都丢失

    android - 检索到的数据未显示在小部件中

    firebase - 如何在另一个小部件中获取Firestore数据