Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ add animation option to setPage() method for Android #251

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import 'package:flutter_pdfview/flutter_pdfview.dart';
| :------------- | :------------------: | :--------: | :------------: |
| getPageCount | Get total page count | - | `Future<int>` |
| getCurrentPage | Get current page | - | `Future<int>` |
| setPage | Go to/Set page | `int page` | `Future<bool>` |
| setPage | Go to/Set page | `int page`<br>`withAnimation` (**Optional**, only works for **Android**, defaults to `false`) | `Future<bool>` |

## Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ void getCurrentPage(Result result) {
void setPage(MethodCall call, Result result) {
if (call.argument("page") != null) {
int page = (int) call.argument("page");
pdfView.jumpTo(page);
boolean withAnimation = call.argument("withAnimation");

pdfView.jumpTo(page, withAnimation);
}

result.success(true);
Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
configurations.all {
resolutionStrategy {
force 'androidx.core:core-ktx:1.6.0'
}
}
}
5 changes: 4 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ class _PDFScreenState extends State<PDFScreen> with WidgetsBindingObserver {
return FloatingActionButton.extended(
label: Text("Go to ${pages! ~/ 2}"),
onPressed: () async {
await snapshot.data!.setPage(pages! ~/ 2);
await snapshot.data!.setPage(
pages! ~/ 2,
withAnimation: true,
);
},
);
}
Expand Down
10 changes: 9 additions & 1 deletion lib/flutter_pdfview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,18 @@ class PDFViewController {
return currentPage;
}

Future<bool?> setPage(int page) async {
/// Moves the PDF to the specified page number.
///
/// [page] is the page number to move to.
///
/// [withAnimation] is whether or not to animate the transition (only works on Android), defaults to `false`.
///
/// Returns `true` if the page was set successfully, otherwise `false`.
Future<bool?> setPage(int page, {bool withAnimation = false}) async {
final bool? isSet =
await _channel.invokeMethod('setPage', <String, dynamic>{
'page': page,
'withAnimation': withAnimation,
});
return isSet;
}
Expand Down