Getting Started with PSPDFKit Flutter

At PSPDFKit, we support all major hybrid technologies, including Flutter, and PSPDFKit Flutter is the newest addition to our growing wrappers family.

What Is Flutter?

Flutter is a relatively new hybrid technology (compared to Cordova, Xamarin, and React Native, which are all at least a few years old) and it’s made by Google. According to Google, “Flutter allows you to build beautiful native apps on iOS and Android from a single codebase.”

Flutter uses Google’s own programming language, Dart, which is somewhat similar to JavaScript and has built-in support for type safety. Flutter has some great features — like hot reload, which allows you to quickly reload an app and view changes without having to restart the app — and it comes with a modern reactive framework and lots of widgets.

When we first looked into using Flutter, we enjoyed the development experience, and our experimenting resulted in the PSPDFKit Flutter wrapper. In this post, I’ll talk about how to get started with PSPDFKit Flutter. I’ll also discuss how easy and fast it is to get our sample project running on both Android and iOS.

There are four simple steps, which you’ll find below.

Step 1: Install the Flutter SDK and the IDEs

Before we get started, we need to make sure that the Flutter SDK, Android Studio, and Xcode are all installed.

ℹ️ Note: If you’re following this tutorial on a single platform, it’s not necessary to install the other platform’s IDE. For example, if you want to run the sample project on Android, it’s unnecessary to install Xcode.

Step 2: Clone the PSPDFKit Flutter Repository

You need to download or clone the open source repository for PSPDFKit Flutter:

1
git clone git@github.com:PSPDFKit/pspdfkit-flutter.git

Step 3: Download and Set Up PSPDFKit

Then, you need to download and set up PSPDFKit for Android and iOS.

Setting Up PSPDFKit for Android

For Android, you need to create a local property file in pspdfkit-flutter/example/android/local.properties and specify the following properties:

local.properties
1
2
3
4
sdk.dir=/path/to/your/Android/sdk
flutter.sdk=/path/to/your/flutter/sdk
pspdfkit.password=YOUR_PASSWORD_GOES_HERE
flutter.buildMode=debug

Setting Up PSPDFKit for iOS

For iOS, replace YOUR_COCOAPODS_KEY_GOES_HERE with your CocoaPods key in pspdfkit-flutter/example/iOS/Podfile, like so:

Copy
1
2
3
4
 ...
 target 'Runner' do
   pod 'PSPDFKit', podspec:'https://customers.pspdfkit.com/cocoapods/YOUR_COCOAPODS_KEY_GOES_HERE/pspdfkit/latest.podspec'
 ...

ℹ️ Important: If you’re an existing customer, you can find the password, CocoaPods key, and license keys in your customer portal. Otherwise, if you don’t already have PSPDFKit, sign up for our 60-day trial and you will receive an email with the instructions to get started.

Now, cd into the pspdfkit-flutter/example directory, and run flutter emulators --launch <EMULATOR_ID> to launch the desired emulator, like so:

1
2
cd pspdfkit-flutter/example
flutter emulators --launch <EMULATOR_ID>

💡 Tip: Optionally, you can repeat this step to launch multiple emulators.

Step 4: Build and Run

The app is ready to start! Run flutter run -d all to deploy the PSPDFKit Flutter example on all your connected devices:

1
flutter run -d all
Android iOS

Conclusion

Flutter allows you to run our example from a single codebase on both Android and iOS. In our example app, the logic is in main.dart, and it contains very little platform-specific code.

Our wrapper, PSPDFKit Flutter, is open source, and we encourage and welcome pull request contributions from the community.

Let us know what you think!

PSPDFKit for iOS

Download the free 60-day trial and add it to your app today.

iOS