Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to pubspec.yaml attributes (version) from Dart app

Tags:

dart

Is there any way to access some of the attributes listed in a pubspec.yaml file in that files Dart application?

In particular, the version and description attributes may be quite useful to see in a version info dialog, or even a '--version' when using a console app. I haven't been able to find a way to access in the API. I'm not sure if Mirrors would have anything appropriate, but if a web app is compiled to JS, then I don't see the description anywhere in the output JS.

Thanks.

EDIT
feature request: https://code.google.com/p/dart/issues/detail?id=18769

like image 761
Dirv Avatar asked May 12 '14 15:05

Dirv


People also ask

How do you get to Pubspec yaml?

From Android Studio/IntelliJ: Click Packages get in the action ribbon at the top of pubspec. yaml . From VS Code: Click Get Packages located in right side of the action ribbon at the top of pubspec. yaml .

What is a Pubspec yaml file in Dart?

Conclusion. The pubspec. yaml file is transversal to all apps and packages - it is where we add metadata to our project, stipulate the Dart and Flutter SDK constraints, manage the dependencies and also set Flutter-specific configurations.

How do you add dependency in Pubspec yaml in flutter?

You can go to the pubspec. yaml file and add dependencies ,under dependencies and then packages get will do the work. or you can run flutter pub get in the terminal.


1 Answers

FOR FLUTTER ONLY

Please use this new package package_info_plus from flutter community.

import 'package:package_info_plus/package_info_plus.dart';  PackageInfo packageInfo = await PackageInfo.fromPlatform();  String appName = packageInfo.appName; String packageName = packageInfo.packageName; String version = packageInfo.version; String buildNumber = packageInfo.buildNumber; 

BELOW SOLUTION IS DEPRICATED.

I know the OP wants to read YAML but for flutter dev's you guys can read the version and other info of the application using package_info.

This is the sample to fetch details from Android/iOS application.

import 'package:package_info/package_info.dart';  PackageInfo packageInfo = await PackageInfo.fromPlatform();  String appName = packageInfo.appName; String packageName = packageInfo.packageName; String version = packageInfo.version; String buildNumber = packageInfo.buildNumber; 
like image 88
Jawand Singh Avatar answered Sep 17 '22 18:09

Jawand Singh