buttonStyle method

  1. @preferInline
ButtonStyle? buttonStyle({
  1. String key = "style",
  2. ButtonStyle? defaultValue,
})

Retrieves a ButtonStyle value from the JSON map for the given key.

Looks up the value associated with key in the JSON. If the value is already a ButtonStyle, it is returned as is. If the value is a Map<String, dynamic>, it attempts to parse it into a ButtonStyle. Otherwise, it returns defaultValue.

  • key: The key to look up in the JSON map. Defaults to 'style'.
  • defaultValue: The value to return if the key is not found or cannot be resolved. Defaults to null.

Returns:

  • A ButtonStyle if the value is valid or can be parsed.
  • defaultValue if the value is not a valid ButtonStyle or cannot be parsed.
  • null if both the value and defaultValue are null.

Implementation

@preferInline
ButtonStyle? buttonStyle({
  String key = "style",
  ButtonStyle? defaultValue,
}) {
  final value = _json[key];

  if (value is ButtonStyle) return value;

  if (value == null) return defaultValue;

  switch (value) {
    case Map<String, dynamic>():
      return _json[key] = _buttonStyleFromMap(value);
    default:
      return defaultValue;
  }
}