Skip to content

Kotlin Flutter Poc #282

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@ rootProject.allprojects {
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 31
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import com.pdftron.common.PDFNetException;
import com.pdftron.pdf.PDFNet;
import com.pdftron.pdftronflutter.FlutterDocumentActivity;
import com.pdftron.pdftronflutter.kotlin.MyToast;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.EventChannel;
@@ -20,6 +21,7 @@
import static com.pdftron.pdftronflutter.helpers.PluginUtils.FUNCTION_OPEN_DOCUMENT;
import static com.pdftron.pdftronflutter.helpers.PluginUtils.FUNCTION_SET_LEADING_NAV_BUTTON_ICON;
import static com.pdftron.pdftronflutter.helpers.PluginUtils.FUNCTION_SET_REQUESTED_ORIENTATION;
import static com.pdftron.pdftronflutter.helpers.PluginUtils.FUNCTION_SHOW_MY_TOAST;
import static com.pdftron.pdftronflutter.helpers.PluginUtils.KEY_CONFIG;
import static com.pdftron.pdftronflutter.helpers.PluginUtils.KEY_DOCUMENT;
import static com.pdftron.pdftronflutter.helpers.PluginUtils.KEY_LEADING_NAV_BUTTON_ICON;
@@ -316,6 +318,10 @@ public void onMethodCall(MethodCall call, Result result) {
FlutterDocumentActivity.setOrientation(requestedOrientation);
break;
}
case FUNCTION_SHOW_MY_TOAST: {
MyToast.show(mContext);
break;
}
default:
PluginUtils.onMethodCall(call, result, FlutterDocumentActivity.getCurrentActivity());
break;
Original file line number Diff line number Diff line change
@@ -354,6 +354,9 @@ public class PluginUtils {
public static final String FUNCTION_SET_VERTICAL_SCROLL_POSITION = "setVerticalScrollPosition";
public static final String FUNCTION_GET_VISIBLE_PAGES = "getVisiblePages";

// Kotlin Toast Method
public static final String FUNCTION_SHOW_MY_TOAST = "showMyToast";

// Hygen Generated Method Constants
public static final String FUNCTION_GET_ANNOTATIONS_ON_PAGE = "getAnnotationsOnPage";

13 changes: 13 additions & 0 deletions android/src/main/java/com/pdftron/pdftronflutter/kotlin/MyToast.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.pdftron.pdftronflutter.kotlin

import android.content.Context
import android.widget.Toast

class MyToast {
companion object {
@JvmStatic
fun show(context: Context) {
Toast.makeText(context, "Kotlin API Called!!!", Toast.LENGTH_SHORT).show()
}
}
}
2 changes: 2 additions & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@ if (flutterVersionName == null) {
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
3 changes: 3 additions & 0 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
buildscript {
ext.kotlin_version = "1.6.20"
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
}
}

2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -208,7 +208,7 @@ class _ViewerState extends State<Viewer> {
// });

// Show a dialog when leading navigation button is pressed.
_showMyDialog();
PdftronFlutter.showMyToast();
});

await controller.openDocument(_document, config: config);
24 changes: 15 additions & 9 deletions lib/pdftron_flutter.dart
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ library pdftron;
import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'src/options.dart';
@@ -24,7 +25,8 @@ class PdftronFlutter {

/// The current version of the OS that the app is running on.
static Future<String> get platformVersion async {
final String version = await _channel.invokeMethod(Functions.getPlatformVersion);
final String version =
await _channel.invokeMethod(Functions.getPlatformVersion);
return version;
}

@@ -43,6 +45,11 @@ class PdftronFlutter {
<String, dynamic>{Parameters.licenseKey: licenseKey});
}

/// Invokes Kotlin Toast API
static Future<void> showMyToast() {
return _channel.invokeMethod(Functions.showMyToast);
}

/// Opens a document in the viewer with configurations.
///
/// Uses the path specified by [document]. Takes a [password] for
@@ -603,7 +610,7 @@ class PdftronFlutter {
static Future<void> exitSearchMode() {
return _channel.invokeMethod(Functions.exitSearchMode);
}

/// Zooms the viewer to the given scale using the given coordinate as the center.
///
/// The zoom center ([x],[y]) is represented in the screen space, whose origin
@@ -612,7 +619,7 @@ class PdftronFlutter {
return _channel.invokeMethod(Functions.zoomWithCenter,
<String, dynamic>{"zoom": zoom, "x": x, "y": y});
}

/// Zooms the viewer to fit the given rectangular area in the specified page.
///
/// ```dart
@@ -710,9 +717,9 @@ class PdftronFlutter {
Parameters.red: red,
Parameters.green: green,
Parameters.blue: blue
});
});
}

/// Gets the horizontal and vertical scroll position in the current document viewer.
///
/// The scroll position is returned as a `Map<String, int>` with the keys
@@ -742,7 +749,7 @@ class PdftronFlutter {
Parameters.verticalScrollPosition: verticalScrollPosition
});
}

/// Gets the page numbers of currently visible pages in the viewer.
static Future<List<int>?> getVisiblePages() {
return _channel.invokeMethod(Functions.getVisiblePages);
@@ -751,9 +758,8 @@ class PdftronFlutter {
// Hygen Generated Methods
/// Gets the list of annotations on the given page.
static Future<List<Annot>?> getAnnotationsOnPage(int pageNumber) {
return _channel.invokeMethod(Functions.getAnnotationsOnPage, <String, dynamic>{
Parameters.pageNumber: pageNumber
}).then((jsonArray) {
return _channel.invokeMethod(Functions.getAnnotationsOnPage,
<String, dynamic>{Parameters.pageNumber: pageNumber}).then((jsonArray) {
List<dynamic> annotations = jsonDecode(jsonArray);
List<Annot> annotList = new List<Annot>.empty(growable: true);
for (dynamic annotation in annotations) {
6 changes: 3 additions & 3 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/// Names of functions.
class Functions {
static const getPlatformVersion = "getPlatformVersion";
@@ -9,6 +8,7 @@ class Functions {
static const getSavedSignatureFolder = "getSavedSignatureFolder";

/// Android only
static const showMyToast = "showMyToast";
static const getSavedSignatureJpgFolder = "getSavedSignatureJpgFolder";
static const importAnnotations = "importAnnotations";
static const exportAnnotations = "exportAnnotations";
@@ -75,7 +75,7 @@ class Functions {
static const getScrollPos = "getScrollPos";
static const setHorizontalScrollPosition = "setHorizontalScrollPosition";
static const setVerticalScrollPosition = "setVerticalScrollPosition";
static const smartZoom = "smartZoom";
static const smartZoom = "smartZoom";
static const getVisiblePages = "getVisiblePages";

// Hygen Generated Methods
@@ -458,4 +458,4 @@ class AnnotationManagerUndoMode {
class ToolbarAlignment {
static const Start = "GravityStart";
static const End = "GravityEnd";
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pdftron_flutter
description: A convenience wrapper to build Flutter apps that use the PDFTron mobile SDK for smooth, flexible, and stand-alone document viewing.
version: 1.0.1-1
version: 1.0.1-3
homepage: https://www.pdftron.com
repository: https://github.com/PDFTron/pdftron-flutter
issue_tracker: https://github.com/PDFTron/pdftron-flutter/issues