attributeToBool function

bool attributeToBool(
  1. String inputValue, {
  2. bool defaultValue = false,
})

Parses HTML attribute String to a bool.

Should be used to parse values passed to @Attribute constructor argument.

This does not follow the HTML boolean attribute definition (https://stackoverflow.com/a/4139805), as 'false' String will be parsed to false value.

When no attribute is present defaultValue value is returned.

NOTE: no attribute is not the same as no value for attribute:

  • <my-component foo> - foo attribute is present but has no value, which is parsed to true.
  • <my-component> - no attribute is present, parsed to defaultValue.

Implementation

bool attributeToBool(String inputValue, {bool defaultValue = false}) {
  return _parseBool(inputValue);
}