You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 18, 2025. It is now read-only.
When using decode() to decode custom types, the class can't be instantiated.
Example:
import'dart:io';
classFoo {
staticfinalFoo one =Foo._('one');
staticfinalFoo two =Foo._('two');
staticfinalFoo three =Foo._('three');
finalString name;
Foo._(this.name);
}
classFooConfigurationimplementsFoo {
Foo _delegate;
FooConfiguration.fromFile(File file) :super.fromFile(file);
FooConfiguration.fromString(String yaml) :super.fromString(yaml);
FooConfiguration.fromMap(Map<dynamic, dynamic> yaml):super.fromMap(yaml);
@overridevoiddecode(dynamic name) {
name = name.toString().toLowerCase();
if (name =='one' ) _delegate =Foo.one;
elseif (name =='two' ) _delegate =Foo.two;
elseif (name =='three') _delegate =Foo.three;
}
@overrideList<String> validate() {
var errors =<String>[];
if (this._delegate ==null) {
errors.add("Invalid value for `foo`. Must be one of one|two|three");
}
return errors;
}
Stringget name => _delegate.name;
}
voidmain() {
// ======== Create Filevar fileContents ='two';
var filePath ='/path/to/example.yaml';
var file =newFile(filePath)..createSync()..writeAsStringSync(fileContents, flush:true);
// ======== Load Filevar foo =newFooConfiguration.fromFile(filePath);
// !!!!!!!!!!!!!!!!!!!!!!!!!// type 'String' is not a subtype of type 'Map<dynamic, dynamic>' in type cast// !!!!!!!!!!!!!!!!!!!!!!!!!
}
This error is coming from /lib/src/configuration.dart:19 which is both assuming and requiring that the contents of the file be a yaml object rather than any other valid yaml datatype.
When using
decode()to decode custom types, the class can't be instantiated.Example:
This error is coming from /lib/src/configuration.dart:19 which is both assuming and requiring that the contents of the file be a yaml object rather than any other valid yaml datatype.
There's a PR to fix this incoming...