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
Learn Golang Tutorials - Rune Types Explained with examples How to display images in Hugo with examples | Hugo Image shortcode Nodejs package.json resolutions How to find Operating System username in NodeJS? How to convert Double to Integer or Integer to double in Dart| Flutter By ExampleRelated posts