有没有办法在FILES DART应用程序中访问pubspec.yaml文件中列出的某些属性?
特别是,在版本信息对话框中查看版本和描述属性可能非常有用,甚至在使用控制台应用程序时可以看到"--version".我还没有找到在API中访问的方法.我不确定Mirrors是否会有任何合适的东西,但如果Web应用程序编译成JS,那么我在输出JS中的任何地方都看不到描述.
谢谢你.
EDIT
有没有办法在FILES DART应用程序中访问pubspec.yaml文件中列出的某些属性?
特别是,在版本信息对话框中查看版本和描述属性可能非常有用,甚至在使用控制台应用程序时可以看到"--version".我还没有找到在API中访问的方法.我不确定Mirrors是否会有任何合适的东西,但如果Web应用程序编译成JS,那么我在输出JS中的任何地方都看不到描述.
谢谢你.
EDIT
您可以安装"dart_config"包,并使用此代码解析pubspec.yaml文件:
import 'package:dart_config/default_server.dart';
import 'dart:async';
void main() {
Future<Map> conf = loadConfig("../pubspec.yaml");
conf.then((Map config) {
print(config['name']);
print(config['description']);
print(config['version']);
print(config['author']);
print(config['homepage']);
print(config['dependencies']);
});
}
输出如下所示:
test_cli
A sample command-line application
0.0.1
Robert Hartung
URL
{dart_config: any}
EDIT个
您可以使用YAML包本身完成此操作:
*注意:这在Flutter 网上不起作用
import 'package:yaml/yaml.dart';
import 'dart:io'; // *** NOTE *** This will not work on Flutter Web
void main() {
File f = new File("../pubspec.yaml");
f.readAsString().then((String text) {
Map yaml = loadYaml(text);
print(yaml['name']);
print(yaml['description']);
print(yaml['version']);
print(yaml['author']);
print(yaml['homepage']);
print(yaml['dependencies']);
});
}
向罗伯特致敬