decodeMaterialStatePropertyBool static method

MaterialStateProperty<bool?>? decodeMaterialStatePropertyBool(
  1. dynamic value, {
  2. bool validate = true,
})

Decodes a value into a double based MaterialStateProperty. This accepts a double or a String which will be resolved for all states.

Alternatively, if the value is a Map then this expects the following format:

{
  "disabled": <bool>,
  "dragged": <bool>,
  "empty": <bool>,
  "error": <bool>,
  "focused": <bool>,
  "hovered": <bool>,
  "pressed": <bool>,
  "scrolledUnder": <bool>,
  "selected": <bool>
}

Implementation

static MaterialStateProperty<bool?>? decodeMaterialStatePropertyBool(
  dynamic value, {
  bool validate = true,
}) {
  MaterialStateProperty<bool?>? result;

  if (value is MaterialStateProperty<bool?>) {
    result = value;
  } else if (value != null) {
    if (value is int || value is double || value is bool || value is String) {
      result = MaterialStateProperty.all<bool?>(JsonClass.parseBool(value));
    } else if (value is Map) {
      assert(SchemaValidator.validate(
        schemaId: '$_baseSchemaUrl/material_state_property_bool',
        value: value,
        validate: validate,
      ));

      result = MaterialStateProperty.resolveWith((states) {
        bool? result;
        if (states.contains(MaterialState.disabled)) {
          result = value['disabled'] == null
              ? null
              : JsonClass.parseBool(value['disabled']);
        } else if (states.contains(MaterialState.dragged)) {
          result = value['dragged'] == null
              ? null
              : JsonClass.parseBool(value['dragged']);
        } else if (states.contains(MaterialState.error)) {
          result = value['error'] == null
              ? null
              : JsonClass.parseBool(value['error']);
        } else if (states.contains(MaterialState.focused)) {
          result = value['focused'] == null
              ? null
              : JsonClass.parseBool(value['focused']);
        } else if (states.contains(MaterialState.hovered)) {
          result = value['hovered'] == null
              ? null
              : JsonClass.parseBool(value['hovered']);
        } else if (states.contains(MaterialState.pressed)) {
          result = value['pressed'] == null
              ? null
              : JsonClass.parseBool(value['pressed']);
        } else if (states.contains(MaterialState.scrolledUnder)) {
          result = value['scrolledUnder'] == null
              ? null
              : JsonClass.parseBool(value['scrolledUnder']);
        } else if (states.contains(MaterialState.selected)) {
          result = value['selected'] == null
              ? null
              : JsonClass.parseBool(value['selected']);
        } else {
          result = value['empty'] == null
              ? null
              : JsonClass.parseBool(value['empty']);
        }

        return result;
      });
    } else {
      result = MaterialStateProperty.all<bool?>(value);
    }
  }
  return result;
}