namedAttribute<T> method
Extracts an attribute from an element, converting it into a desired type.
Looks for the named attribute on the supplied element, supplying a
converter automatically if possible. Returns the value if found,
null if not found, or throws Future.error if not found and
marked as required.
T the type to return
elementFuture the start tag
attributeName the name of the attribute to find. Accepts fully
qualified or unqualified names.
convert (optional) if supplied, applies a converter of the form
T Function (String s) to the found value. If not supplied,
calls autoConverter(T) to find a converter.
isRequired (optional) if true, throws a Future.error if the
attribute isn't found.
defaultValue (optional) if supplied, a missing attribute will return
this value instead.
Typical call:
final name = _pr.namedAttribute<String>(_startTag, 'name')
Implementation
@Deprecated('use `attribute` or `optionalAttribute`')
Future<T?> namedAttribute<T>(String attributeName,
{Converter<T>? convert, isRequired = false, T? defaultValue}) async {
final probe = await optionalAttribute<T>(attributeName, convert: convert);
if (probe == null && isRequired) {
throw MissingAttribute(name, attributeName);
}
return probe ?? defaultValue;
}