the package yaml 2.2.1 helps Flutter users to read in YAML files. Unfortunately, the documentation is not enlightening me
import 'dart:convert';
import 'package:yaml/yaml.dart';
main() {
// load a YAML file
var doc = loadYaml("YAML: YAML Ain't Markup Language");
print(doc['YAML']);
// Encode a YAML file
print(json.encode(doc));
}
I put a YAML file in the folder
assets/yamlfiles/yamltoberead.yml
and wrote the necessary lines in the pubspec.yaml file.
I assume, I have to change the line "YAML: YAML Ain't ..." to the relative path of the yamltoberead.yml file, but it is throwing errors
type 'String' is not a subtype of type 'int' of 'index'
Is there another way to read in YAML files or how to fix the error?
pubspec.yaml
file?yaml: ^2.2.1
File('file.yaml').readAsString().then((String contents) { var doc = loadYaml(contents); });
File(yamlPath).readAsString().then(loadYaml)
- shorter version of the above answer