setTextStyle method

void setTextStyle(
  1. List<TextStyle> newstyle
)

Implementation

void setTextStyle(List<TextStyle> newstyle) {
  //only support color, weight, family, fontstyle
  textlist = [];
  textCenter = [];
  textPoints = [];
  isdrawed = [];

  for (var i = 0; i < data.length; i++) {
    double getTextSize =
        (minTextSize * (data[0]['value'] - data[i]['value']) +
                maxTextSize *
                    (data[i]['value'] - data[data.length - 1]['value'])) /
            (data[0]['value'] - data[data.length - 1]['value']);

    final textSpan = TextSpan(
      text: data[i]['word'],
      style: TextStyle(
        color: newstyle[i].color,
        fontSize: getTextSize,
        fontWeight: newstyle[i].fontWeight,
        fontFamily: newstyle[i].fontFamily,
        fontStyle: newstyle[i].fontStyle,
      ),
    );

    final textPainter = TextPainter()
      ..text = textSpan
      ..textDirection = TextDirection.ltr
      ..textAlign = TextAlign.center
      ..layout();

    textlist.add(textPainter);

    double centerCorrectionX = centerX - textlist[i].width / 2;
    double centerCorrectionY = centerY - textlist[i].height / 2;
    textCenter.add([centerCorrectionX, centerCorrectionY]);
    textPoints.add([]);
    isdrawed.add(false);
  }
}