Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i add user defined variable in pubspec.yaml for flutter?

Tags:

yaml

flutter

dart

Basically I required to assign version and my local dependencies URL as user defined variable and assign the same in the path or wherever I wish to

Example like below

   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

In Android I can achieve as below

dagger_version=2.8

"com.google.dagger:dagger:${dagger_version}" 
like image 653
Askarc Ali Avatar asked Nov 12 '20 12:11

Askarc Ali


People also ask

What is the use of Pubspec yaml in flutter?

Every Flutter project includes a pubspec. yaml file, often referred to as the pubspec. A basic pubspec is generated when you create a new Flutter project. It's located at the top of the project tree and contains metadata about the project that the Dart and Flutter tooling needs to know.


1 Answers

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

  • the answer to the above is No, it is not possible because pubspec.yaml does not support imports.

  • Now for your main question : you can use YAML Anchors and Aliases for example :

    # 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 because I'm not sure of the syntax but this should help with what you are looking for

like image 128
Asmoun Avatar answered Oct 16 '22 17:10

Asmoun