PDF Tech

How to use Flutter with Foxit PDF SDK for Android

by Conor Smith | February 27, 2019

We’ve recently developed a new plugin for our mobile framework projects using Google’s Flutter tool. Although a relatively early development tool in the public market, Flutter already powers many large-size applications today and has received great traction on app development since its release in November 2018. If you haven’t heard about Flutter before, grab yourself a chair.

Flutter is Google’s open source cross-platform mobile UI development kit. It makes building high-quality native interfaces in Android and iOS much faster and easier. Based on Google’s in-house Dart programming language, Flutter is not a JavaScript-based framework like React Native or Cordova. That means the implementation does not require a JavaScript engine nor native controls. It uses its own high-performance rendering engine (C/C++, Dart, and Skia 2D rendering engines to draw widgets). This wider stack of features makes Flutter not only a framework, but a full development kit for cross-platform mobile development.

We believe the comparison between Flutter and JavaScript-based frameworks is important here for many reasons, but we want to focus on Flutter’s hot reload feature. It allows users to quickly reload and update changes to the application in the device or emulator, much like JavaScript has done with the optimizations from JIT development.

On the hot reload process, Flutter uses Dart processes that scan the code for changes and converts only the specific parts of the library needed to perform the change into kernel files. These files are pushed back to Dart’s virtual machine and therefore to the application. This system call running in the background process of the machine requires only a small amount of code to be re-processed, which makes loading/rendering much faster. The performance may vary depending on the size and complexity of the application, but the numbers have been exceptionally fast so far.

 


Combining quick rendering functionality into complex development tools like Flutter is similar to the way we make our SDKs better on cross-platform development. This is why we thought it would be important to add Flutter to our list of supported cross-platform plugins alongside React Native, Cordova and Xamarin.

Next, let’s talk about how to use the Foxit PDF SDK in the Flutter app in a few quick steps. Currently, we support the Android version of the plugin. Once you are familiar with Flutter and have created a project, add the Flutter plugin for the Foxit PDF SDK to the project dependencies as follows:

1. First, in your pubspec.yaml file, add the following:

dependencies:
 flutter:
 sdk: flutter

 flutter_foxitpdf:
 git:
 url: git://github.com/foxitsoftware/flutter-foxitpdf.git


2.
Then, in your app’s build.gradle file:

allprojects { 
 repositories { 
 google() 
 jcenter() 
 flatDir { 
 dirs project(':flutter_foxitpdf').file("$rootDir/libs") 
 } 
 } 
 }


3.
And finally in the AndroidManifest.xml file:

<application 
 android:name="io.flutter.app.FlutterApplication" 
 android:label="testflutter" 
 android:icon="@mipmap/ic_launcher" 
 tools:replace="android:label">

 

Plugin Usage
To call functions in the plugin, follow the steps below:

1. Import the plugin in the main.dart file

import 'package:flutter_foxitpdf/flutter_foxitpdf.dart';


2.
Replace YOUR_RDK_SN and YOUR_RDK_KEY with your own license (rdk_key.txt, rdk_sn.txt) from your Foxit PDF SDK for Android package

class _MyAppState extends State<MyApp> { 
 String _platformVersion = 'Unknown'; 
 int _error = -1; 
 
 String _sn = 'YOUR_RDK_SN'; 
 String _key = 'YOUR_RDK_KEY';


3.
Call the OpenDocument function in order to run our full-feature PDFReader using Flutter

openDocument(_path, null);

 

And done! You should be able to load a file in Foxit PDF SDK for Android quickly using Flutter. Click here to contact our team and test our Flutter plugin today.