encodeButtonStyle static method

Map<String, dynamic>? encodeButtonStyle(
  1. ButtonStyle? value
)

Encodes the given value into a JSON representation.

{
  "alignment": <AlignmentGeometry>,
  "animationDuration": <MaterialStateProperty<double>>,
  "backgroundColor": <MaterialStateProperty<Color>>,
  "elevation": <MaterialStateProperty<double>>,
  "enableFeedback": <bool>,
  "foregroundColor": <MaterialStateProperty<Color>>,
  "minimumSize": <MaterialStateProperty<Size>>,
  "mouseCursor": <MaterialStateProperty<MouseCursor>>,
  "overlayColor": <MaterialStateProperty<Color>>,
  "padding": <MaterialStateProperty<EdgeInsetsGeometry>>,
  "shadowColor": <MaterialStateProperty<Color>>,
  "shape": <MaterialStateProperty<OutlinedBorder>>,
  "side": <MaterialStateProperty<BorderSide>>,
  "tapTargetSize": <MaterialTapTargetSize>,
  "textStyle": <MaterialStateProperty<TextStyle>>,
  "visualDensity": <VisualDensity>
}

This won't maintain the MaterialStateProperty of each corresponding property, instead will resolve them by using an empty set of states, returning and encoding the resolved object.

See also:

Implementation

static Map<String, dynamic>? encodeButtonStyle(
  ButtonStyle? value,
) {
  Map<String, dynamic>? result;

  if (value != null) {
    result = <String, dynamic>{
      'alignment': encodeAlignment(value.alignment as Alignment?),
      'animationDuration': value.animationDuration?.inMilliseconds,
      'backgroundColor': encodeMaterialStatePropertyColor(
        value.backgroundColor,
      ),
      'elevation': encodeMaterialStatePropertyDouble(value.elevation),
      'enableFeedback': value.enableFeedback,
      'foregroundColor': encodeMaterialStatePropertyColor(
        value.foregroundColor,
      ),
      'minimumSize': encodeMaterialStatePropertySize(value.minimumSize),
      'mouseCursor': encodeMaterialStatePropertyMouseCursor(
        value.mouseCursor,
      ),
      'overlayColor': encodeMaterialStatePropertyColor(value.overlayColor),
      'padding': encodeMaterialStatePropertyEdgeInsetsGeometry(value.padding),
      'shadowColor': encodeMaterialStatePropertyColor(value.shadowColor),
      'shape': encodeMaterialStatePropertyOutlinedBorder(value.shape),
      'side': encodeMaterialStatePropertyBorderSide(value.side),
      'tapTargetSize': encodeMaterialTapTargetSize(
        value.tapTargetSize,
      ),
      'textStyle': encodeMaterialStatePropertyTextStyle(value.textStyle),
      'visualDensity': encodeVisualDensity(
        value.visualDensity,
      ),
    };
  }

  return _stripNull(result);
}