Skip to content

Commit

Permalink
Update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
espresso3389 committed Jan 30, 2024
1 parent e8e61df commit 3bf9be5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
9 changes: 9 additions & 0 deletions lib/src/pdf_document_ref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ typedef PdfDocumentLoaderProgressCallback = void Function(int progress,
[int? total]);

/// PdfDocumentRef controls loading of a [PdfDocument].
/// There are several types of [PdfDocumentRef]s predefined:
/// * [PdfDocumentRefAsset] loads the document from asset.
/// * [PdfDocumentRefUri] loads the document from network.
/// * [PdfDocumentRefFile] loads the document from file.
/// * [PdfDocumentRefData] loads the document from data in [Uint8List].
/// * [PdfDocumentRefCustom] loads the document from custom source.
/// * [PdfDocumentRefDirect] directly contains [PdfDocument].
///
/// Or you can create your own [PdfDocumentRef] by extending the class.
abstract class PdfDocumentRef {
const PdfDocumentRef({
this.autoDispose = true,
Expand Down
60 changes: 41 additions & 19 deletions lib/src/widgets/pdf_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ import 'pdf_viewer_params.dart';
/// A widget to display PDF document.
///
/// To create a [PdfViewer] widget, use one of the following constructors:
/// - [PdfViewer.asset]
/// - [PdfViewer.file]
/// - [PdfViewer.uri]
/// - [PdfViewer.documentRef]
/// - [PdfDocument] with [PdfViewer.documentRef]
/// - [PdfViewer.asset] with an asset name
/// - [PdfViewer.file] with a file path
/// - [PdfViewer.uri] with a URI
///
/// Of course, if you have a [PdfDocument] use [PdfViewer] constructor:
/// - [PdfViewer]
/// Or otherwise, you can pass [PdfDocumentRef] to [PdfViewer] constructor.
class PdfViewer extends StatefulWidget {
/// Create [PdfViewer] using [PdfDocument].
/// Create [PdfViewer] from a [PdfDocumentRef].
///
/// [documentRef] is the [PdfDocumentRef].
/// [controller] is the controller to control the viewer.
/// [params] is the parameters to customize the viewer.
/// [initialPageNumber] is the page number to show initially.
PdfViewer({
required PdfDocument document,
const PdfViewer(
this.documentRef, {
super.key,
this.controller,
this.params = const PdfViewerParams(),
this.initialPageNumber = 1,
}) : documentRef = PdfDocumentRefDirect(document);
});

/// Create [PdfViewer] from an asset.
///
Expand Down Expand Up @@ -113,20 +113,42 @@ class PdfViewer extends StatefulWidget {
firstAttemptByEmptyPassword: firstAttemptByEmptyPassword,
);

/// Create [PdfViewer] from a [PdfDocumentRef].
///
/// [documentRef] is the [PdfDocumentRef].
/// [controller] is the controller to control the viewer.
/// [params] is the parameters to customize the viewer.
/// [initialPageNumber] is the page number to show initially.
const PdfViewer.documentRef({
required this.documentRef,
PdfViewer.data(
Uint8List data, {
required String sourceName,
PdfPasswordProvider? passwordProvider,
bool firstAttemptByEmptyPassword = true,
super.key,
this.controller,
this.params = const PdfViewerParams(),
this.initialPageNumber = 1,
});
}) : documentRef = PdfDocumentRefData(
data,
sourceName: sourceName,
passwordProvider: passwordProvider,
firstAttemptByEmptyPassword: firstAttemptByEmptyPassword,
);

PdfViewer.custom({
required int fileSize,
required FutureOr<int> Function(Uint8List buffer, int position, int size)
read,
required String sourceName,
PdfPasswordProvider? passwordProvider,
bool firstAttemptByEmptyPassword = true,
super.key,
this.controller,
this.params = const PdfViewerParams(),
this.initialPageNumber = 1,
}) : documentRef = PdfDocumentRefCustom(
fileSize: fileSize,
read: read,
sourceName: sourceName,
passwordProvider: passwordProvider,
firstAttemptByEmptyPassword: firstAttemptByEmptyPassword,
);

/// [PdfDocumentRef] that represents the PDF document.
final PdfDocumentRef documentRef;

/// Controller to control the viewer.
Expand Down

0 comments on commit 3bf9be5

Please sign in to comment.