ArcTextPainter constructor

ArcTextPainter({
  1. required num radius,
  2. required String text,
  3. TextStyle? textStyle,
  4. StartAngleAlignment alignment = StartAngleAlignment.start,
  5. double initialAngle = 0,
  6. Direction direction = Direction.clockwise,
  7. Placement placement = Placement.outside,
  8. double? stretchAngle,
  9. double? interLetterAngle,
})

Implementation

ArcTextPainter({
  required num radius,
  required String text,
  TextStyle? textStyle,
  StartAngleAlignment alignment = StartAngleAlignment.start,
  double initialAngle = 0,
  this.direction = Direction.clockwise,
  Placement placement = Placement.outside,
  double? stretchAngle,
  double? interLetterAngle,
})  : assert(
        stretchAngle == null || interLetterAngle == null,
        'stretchAngle and interLetterAngle should not be both not null',
      ),
      radius = radius.toDouble(),
      _text = text,
      _textStyle = textStyle {
  _textPainter
    ..text = TextSpan(text: _text, style: textStyle)
    ..layout(minWidth: 0, maxWidth: double.maxFinite);

  switch (placement) {
    case Placement.inside:
      _effectiveRadius = this.radius - _textPainter.height;
    case Placement.outside:
      _effectiveRadius = this.radius;
    case Placement.middle:
      _effectiveRadius = this.radius - _textPainter.height / 2;
  }

  _interLetterAngle = (stretchAngle != null && _text.characters.length > 1)
      ? (stretchAngle -
              _calculateSweepAngle(
                _textPainter,
                _textStyle,
                _effectiveRadius,
                _text,
                0,
              )) /
          _text.characters.length
      : interLetterAngle ?? 0;

  final double alignmentOffset =
      _getAlignmentOffset(alignment, stretchAngle ?? sweepAngle);
  switch (direction) {
    case Direction.clockwise:
      _angleWithAlignment = initialAngle + alignmentOffset;
      _angleMultiplier = 1;
      _heightOffset = -_effectiveRadius - _textPainter.height;
    case Direction.counterClockwise:
      _angleWithAlignment = initialAngle - alignmentOffset + math.pi;
      _angleMultiplier = -1;
      _heightOffset = _effectiveRadius;
  }
}