Skip to content

Commit

Permalink
[native_pdf_view] Added onPageChanged callback. Bump 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeShkurko committed Dec 13, 2019
1 parent 87bca36 commit d4719bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
14 changes: 12 additions & 2 deletions packages/native_pdf_renderer/test/native_pdf_renderer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ void main() {

test('open', () async {
// page number 0 - not available
expect(document.getPage(0), throwsA(isInstanceOf<PdfPageNotFound>()));
expect(
document.getPage(0),
throwsA(
isInstanceOf<PdfNotSupportException>(),
),
);

page = await document.getPage(3);
expect(log, <Matcher>[
Expand All @@ -117,7 +122,12 @@ void main() {
expect(page.document, document);

// page number 4 more than the document
expect(document.getPage(4), throwsA(isInstanceOf<PdfPageNotFound>()));
expect(
document.getPage(4),
throwsA(
isInstanceOf<PdfNotSupportException>(),
),
);
});

test('render', () async {
Expand Down
4 changes: 4 additions & 0 deletions packages/native_pdf_view/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.0

* Added `onPageChanged` callback

## 2.0.0

* Removed default padding
Expand Down
6 changes: 6 additions & 0 deletions packages/native_pdf_view/lib/src/native_pdf_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PDFView extends StatefulWidget {
const PDFView({
@required this.document,
this.controller,
this.onPageChanged,
this.loader = const SizedBox(),
this.scrollDirection = Axis.horizontal,
this.renderer = _render,
Expand All @@ -27,6 +28,7 @@ class PDFView extends StatefulWidget {
@required this.document,
@required this.builder,
this.controller,
this.onPageChanged,
this.loader = const SizedBox(),
this.scrollDirection = Axis.horizontal,
this.renderer = _render,
Expand All @@ -52,6 +54,9 @@ class PDFView extends StatefulWidget {
/// Page management
final PageController controller;

/// Called whenever the page in the center of the viewport changes
final void Function(int page) onPageChanged;

/// Default PdfRenderer options
static Future<PDFPageImage> _render(PDFPage page) => page.render(
width: page.width * 2,
Expand Down Expand Up @@ -169,6 +174,7 @@ class _PDFViewState extends State<PDFView> {
itemCount: widget.document.pagesCount,
onPageChanged: (int index) {
_currentIndex = index;
widget.onPageChanged?.call(index+1);
},
controller: widget.controller ?? _pageController,
scrollDirection: widget.scrollDirection,
Expand Down
2 changes: 1 addition & 1 deletion packages/native_pdf_view/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: native_pdf_view
description: Flutter plugin to render PDF files on both Android and iOS devices. Provides a Widget to render the pages using a PageView.
version: 2.0.0
version: 2.1.0
author: Serge Shkurko <sergeshkurko@outlook.com>
homepage: https://github.com/rbcprolabs/packages.flutter/tree/master/packages/native_pdf_view

Expand Down

0 comments on commit d4719bf

Please sign in to comment.