decodeAlignment static method

Alignment? decodeAlignment(
  1. dynamic value, {
  2. bool validate = true,
})

Decodes the given value to an Alignment. Supported values are:

  • bottomCenter
  • bottomLeft
  • bottomRight
  • center
  • centerLeft
  • centerRight
  • topCenter
  • topLeft
  • topRight

Implementation

static Alignment? decodeAlignment(
  dynamic value, {
  bool validate = true,
}) {
  Alignment? result;

  if (value is Alignment) {
    result = value;
  } else {
    _checkSupported(
      'Alignment',
      [
        'bottomCenter',
        'bottomLeft',
        'bottomRight',
        'center',
        'centerLeft',
        'centerRight',
        'topCenter',
        'topLeft',
        'topRight',
      ],
      value,
    );

    if (value != null) {
      assert(SchemaValidator.validate(
        schemaId: '$_baseSchemaUrl/alignment',
        value: value,
        validate: validate,
      ));
      switch (value) {
        case 'bottomCenter':
          result = Alignment.bottomCenter;
          break;
        case 'bottomLeft':
          result = Alignment.bottomLeft;
          break;
        case 'bottomRight':
          result = Alignment.bottomRight;
          break;
        case 'center':
          result = Alignment.center;
          break;
        case 'centerLeft':
          result = Alignment.centerLeft;
          break;
        case 'centerRight':
          result = Alignment.centerRight;
          break;
        case 'topCenter':
          result = Alignment.topCenter;
          break;
        case 'topLeft':
          result = Alignment.topLeft;
          break;
        case 'topRight':
          result = Alignment.topRight;
          break;
      }
    }
  }

  return result;
}