locateProgression method

  1. @override
Future<Locator?> locateProgression(
  1. double totalProgression
)
override

Locates the target at the given totalProgression relative to the whole publication.

Implementation

@override
Future<Locator?> locateProgression(double totalProgression) async {
  if (totalProgression < 0.0 || 1.0 < totalProgression) {
    Fimber.e(
        "Progression must be between 0.0 and 1.0, received $totalProgression)");
    return null;
  }
  List<List<Locator>> positions = await positionsByReadingOrder();
  _Position? position = _findClosestTo(totalProgression, positions);
  if (position == null) {
    return null;
  }
  Locator locator = position.locator;
  return locator.copyWithLocations(
    progression: _resourceProgressionFor(totalProgression, positions,
            readingOrderIndex: position.readingOrderIndex) ??
        locator.locations.progression,
    totalProgression: totalProgression,
  );
}