toFutureString method

Future<String> toFutureString()

Implementation

Future<String> toFutureString() async {
  /// use `StringBuffer` to add string
  final buffer = StringBuffer(
    "drawtext=text='$text':fontsize=$fontsize:fontcolor=${fontcolor.toHex}:",
  )

    /// set `x` position
    ..write("x=${x ?? '(W-tw)/2'}:y=${y ?? '(H-th)/2'}:");

  /// set `bgcolor` value
  if (bgcolor != null) buffer.write('box=1:boxcolor=${bgcolor!.toHex}:');

  /// set start and end duration
  if (start != null || end != null) {
    buffer.write("enable='between(t,${start ?? 0},${end ?? 'inf'})'");
  }

  if (fontFile != null) {
    var path = fontFile!.path;

    if (fontFile!.type == FileType.file) {
      path = await moveAssetToTemp(path);
    }

    buffer.write(":fontfile='$path'");
  }

  /// set `rotate` value
  if (rotate != null) buffer.write(',rotate=$rotate*PI/180');

  return buffer.toString();
}