THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
This tutorial explains how to read pubspec.yaml file in the example.
pubspec.yaml file contains the following things
name: dartapp
description: >-
dart example application.
version: 1.0.0
environment:
sdk: '>=2.10.0 <3.0.0'
dependencies:
ini: ^2.1.0
jiffy: ^5.0.0
quiver: 3.0.1+1
yaml: ^3.1.0
yaml_writer: 1.0.1
image: any
mime: any
path: any
package_info: any
dev_dependencies:
intl: any
This tutorial is about reading the puspect.yaml file and print the content.
yaml package provides functions for reading yaml syntax files.
readAsString
, which returns Future<String>
with given yaml content.Map[key]
syntax.Here is an example program to read pubspec.yaml file
import 'package:yaml/yaml.dart';
import 'dart:io';
void main() {
File file = new File("pubspec.yaml");
file.readAsString().then((String content) {
Map yaml = loadYaml(content);
print(yaml['name']);
print(yaml['description']);
print(yaml['version']);
print(yaml['dependencies']);
print(yaml['dev_dependencies']);
});
}
Output:
dartapp
dart example application.
1.0.0
{ini: ^2.1.0, jiffy: ^5.0.0, quiver: 3.0.1+1, yaml: ^3.1.0, yaml_writer: 1.0.1, image: any, mime: any, path: any, package_info: any}
{intl: any}
🧮 Tags
Recent posts
Julia examples - Variable Type Nim example - Convert String to/from the Int How to get length of an array and sequence in Nim? Nim environment variables - read, set, delete, exists, and iterate examples? How to convert from single character to/from string in Nim?Related posts