addTextOverlay method

void addTextOverlay({
  1. required String text,
  2. double fontSize = 64,
  3. Color color = VideoEditorColors.onMedia,
  4. TextOverlayStyle style = TextOverlayStyle.outline,
  5. Color? backgroundColor,
  6. bool bold = true,
  7. String? stickerPath,
  8. String idPrefix = 'text',
})

Adds a text overlay at the playhead, visible for three seconds (or until the end of the project).

Implementation

void addTextOverlay({
  required String text,
  double fontSize = 64,
  Color color = VideoEditorColors.onMedia,
  TextOverlayStyle style = TextOverlayStyle.outline,
  Color? backgroundColor,
  bool bold = true,
  String? stickerPath,
  String idPrefix = 'text',
}) {
  final total = totalDuration;
  var startTime = _currentGlobalTime.value;
  var endTime = startTime + const Duration(seconds: 3);
  if (total > Duration.zero) {
    if (endTime > total) endTime = total;
    // At the very end of the project: show the last three seconds instead.
    if (endTime - startTime < const Duration(milliseconds: 500)) {
      startTime = total - const Duration(seconds: 3);
      if (startTime < Duration.zero) startTime = Duration.zero;
      endTime = total;
    }
  }

  final id = '${idPrefix}_${DateTime.now().microsecondsSinceEpoch}';
  textController.addTextOverlay(VideoTextOverlay(
    id: id,
    text: text,
    fontSize: fontSize,
    color: color,
    x: 0.5,
    y: 0.5,
    startTime: startTime,
    endTime: endTime,
    style: style,
    backgroundColor: backgroundColor ?? VideoEditorColors.textLabelBackground,
    bold: bold,
    stickerPath: stickerPath,
  ));
  _selectedTrackType = VideoTrackType.text;
  _activeTrack = VideoTrackType.text;
  _saveState();
  notifyListeners();
}