DVApiScopes.fromConfig constructor
Reads the dartvel.platformApi map from pubspec.yaml.
A scope is either a list of actions or {actions: [...], description: ...}; the description is the wording a consent screen shows.
Implementation
factory DVApiScopes.fromConfig(Map<String, Object?> platformApi) {
final Object? declared = platformApi['scopes'];
final Map<String, List<String>> scopes = <String, List<String>>{};
final Map<String, String> descriptions = <String, String>{};
if (declared is Map) {
for (final MapEntry<Object?, Object?> entry in declared.entries) {
final String name = '${entry.key}';
final Object? value = entry.value;
if (value is List) {
scopes[name] = <String>[for (final Object? a in value) '$a'];
} else if (value is Map) {
final Object? actions = value['actions'];
scopes[name] = <String>[
if (actions is List)
for (final Object? a in actions) '$a',
];
final Object? description = value['description'];
if (description != null) descriptions[name] = '$description';
} else {
throw ArgumentError.value(
value,
name,
'a scope is a list of policy actions',
);
}
}
}
return DVApiScopes(scopes, descriptions: descriptions);
}