0 purchases
yaml2dart
yaml2dart #
Converts a YAML file to a Dart file containing global scope constants. It allows developers to easily use YAML data in their Dart projects by generating a separate file with all the YAML data as constants. Especially good for pubspec.yaml.
Getting started #
dart pub add yaml2dart
copied to clipboard
Usage #
Assuming that the example.yaml file contains the following:
name: "My Project"
version: "1.0.0"
copied to clipboard
The code is:
import 'package:yaml2dart/yaml2dart.dart';
void main() async {
// Create a converter instance with the input and output file paths.
final converter = Yaml2Dart('pub.yaml', 'lib/example_constants.dart');
// Convert the YAML to Dart.
await converter.convert();
}
copied to clipboard
The example_constants.dart file will be generated with the following content:
const exampleName = 'My Project';
const exampleVersion = '1.0.0';
copied to clipboard
To test:
// Use the generated constants in your project.
import 'package:my_project/example_constants.dart';
print('Example name: $exampleName');
print('Example version: $exampleVersion');
copied to clipboard
LICENSE #
BSD 3-Clause License
CONTRIBUTE #
If you have an idea for a new feature or have found a bug, just do a pull request (PR).
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.