Publication constructor

Publication({
  1. required Manifest manifest,
  2. Fetcher fetcher = const EmptyFetcher(),
  3. ServicesBuilder? servicesBuilder,
  4. Map<ReadiumCSSName, bool> userSettingsUIPreset = const {},
  5. String? cssStyle,
})

Implementation

Publication({
  required this.manifest,
  this.fetcher = const EmptyFetcher(),
  ServicesBuilder? servicesBuilder,
  this.userSettingsUIPreset = const {},
  this.cssStyle,
}) {
  // We use a Ref<Publication> instead of passing directly `this` to the services to prevent
  // them from using the Publication before it is fully initialized.
  Ref<Publication> pubRef = Ref<Publication>();
  servicesBuilder ??= ServicesBuilder.create();

  _services = servicesBuilder
      .build(PublicationServiceContext(pubRef, manifest, fetcher));
  _manifest = manifest.copy(
      links: manifest.links +
          _services.map((it) => it.links).flatten().toList());

  pubRef.ref = this;
}