resolve method
Resolves a resource.
- Without a
context(nor defaultContext): returns defaultResource, or the first added option. - With a
context: returns the option with an equal context, otherwise the option with the next greater context (options with anullcontext are greater than any context). Ifcontextis greater than all the options contexts, returns the greatest option.
Contexts are compared with contextComparator, if provided, otherwise with Comparable.compareTo.
Implementation
T? resolve(String key, [C? context]) {
var options = _resources[key];
if (isEmptyObject(options)) return defaultResource?.resource;
context ??= defaultContext;
if (context == null) {
return (defaultResource ?? options!.first).resource;
}
var sortedOptions = _resourcesSorted.putIfAbsent(key, () {
var list = options!.toList();
list.sort((a, b) => _compareContexts(a.context, b.context));
return list;
});
return _getResource(sortedOptions, context).resource;
}