addHighlight function

void addHighlight(
  1. TextSelection selection, {
  2. int color = 0xFFFFCC00,
  3. required highlight_type type,
  4. required String sectionFileName,
  5. required ReaderBloc readerBloc,
})

Implementation

void addHighlight(TextSelection selection,
    {int color = 0xFFFFCC00,
    required highlight_type type,
    required String sectionFileName,
    required ReaderBloc readerBloc}) {
  if (selection.baseOffset == -1) return;
  final newHighlight = Highlight(
      color: color,
      baseOffset: selection.baseOffset,
      extendOffset: selection.extentOffset,
      type: type);

  readerBloc.highlights.add(
    newHighlight,
  );

  readerBloc.highlights.sort((a, b) => a.compareTo(b));

  print(readerBloc.highlights.last);
  readerBloc.saveHighlights();
}