convertNodeToButtonType function

void convertNodeToButtonType(
  1. ButtonTypeEnum type,
  2. ButtonNode node
)

Implementation

void convertNodeToButtonType(ButtonTypeEnum type, ButtonNode node) {
  switch (type) {
    case ButtonTypeEnum.elevated:
      final brightness = ThemeData.estimateBrightnessForColor(
          node.properties.buttonColor.toFlutterColor());
      final color =
          (brightness == Brightness.light ? Colors.black : Colors.white)
              .toColorRGBA();
      node.properties
        ..labelStyle = node.properties.labelStyle.copyWith(fills: [
          color.toPaint(node.properties.labelStyle.fills.firstOrNull?.id)
        ])
        ..icon = node.properties.icon
            .copyWith(color: color.toFlutterColor().toColorRGBA())
        ..buttonColor = node.properties.buttonColor.copyWith(a: 1)
        ..elevation = 8
        ..gap = node.properties.icon.show ? 8 : 0
        ..shape = CShapeBorder.roundedRectangle
        ..borderColor = null
        ..borderWidth = null;
    case ButtonTypeEnum.text:
      node.properties
        ..buttonColor = node.properties.buttonColor.copyWith(a: 0.1)
        ..labelStyle = node.properties.labelStyle.copyWith(fills: [
          node.properties.buttonColor
              .copyWith(a: 1)
              .toPaint(node.properties.labelStyle.fills.firstOrNull?.id)
        ])
        ..icon = node.properties.icon
            .copyWith(color: node.properties.buttonColor.copyWith(a: 1))
        ..elevation = 0
        ..shape = CShapeBorder.roundedRectangle
        ..borderWidth = null
        ..borderColor = null;
    case ButtonTypeEnum.outlined:
      node.properties
        ..buttonColor = node.properties.buttonColor.copyWith(a: 1)
        ..labelStyle = node.properties.labelStyle.copyWith(fills: [
          node.properties.buttonColor
              .copyWith(a: 1)
              .toPaint(node.properties.labelStyle.fills.firstOrNull?.id)
        ])
        ..icon = node.properties.icon
            .copyWith(color: node.properties.buttonColor.copyWith(a: 1))
        ..elevation = 0
        ..shape = CShapeBorder.roundedRectangle
        ..borderWidth = 1
        ..borderColor = null;
    case ButtonTypeEnum.icon:
      final brightness = ThemeData.estimateBrightnessForColor(
          node.properties.buttonColor.toFlutterColor());
      final color =
          (brightness == Brightness.light ? Colors.black : Colors.white)
              .toColorRGBA();
      node.properties
        ..labelStyle = node.properties.labelStyle.copyWith(fills: [
          color.toPaint(node.properties.labelStyle.fills.firstOrNull?.id)
        ])
        ..icon = node.properties.icon.copyWith(color: color)
        ..buttonColor = node.properties.buttonColor.copyWith(a: 1)
        ..icon = node.properties.icon.copyWith(show: true)
        ..shape = CShapeBorder.circle
        ..gap = 0
        ..elevation = 2
        ..borderColor = null
        ..borderWidth = null;
  }
  if (node.properties.buttonType == ButtonTypeEnum.icon) {
    transformNodeFromIconButton(node);
  } else if (type == ButtonTypeEnum.icon) {
    transformNodeToIconButton(node);
  }
  node.properties.buttonType = type;
}