Nutrient 4 migration guide

Nutrient Flutter SDK 4 introduces a significant update with native API bridging using Pigeon, a change that requires updating your project to utilize the new API. This guide will help you transition to the new API, including relocating and renaming some classes and methods.

Follow this guide to ensure your project is compatible with Nutrient Flutter SDK 4.

Removed APIs

  1. The paths pspdfkit-flutter/lib/widgets/pspdfkit_widget.dart and pspdfkit-flutter/lib/widgets/pspdfkit_widget_controller.dart have been removed. Instead, use package:pspdfkit_flutter/pspdfkit_pspdfkit.dart for all imports.

  2. The optional parameters for measurementScale and measurementPrecision have been removed from Pspdfkit.present. Use the measurementValueConfigurations option in PdfConfiguration instead.

Deprecated APIs

The following APIs have been deprecated in Nutrient Flutter SDK 4.

  1. Pspdfkit.setLicenseKey and Pspdfkit.setLicenseKeys have been deprecated. Use Pspdfkit.initialize instead:

Pspdfkit.initialize(
    androidLicenseKey: 'YOUR_ANDROID_LICENSE_KEY',
    iosLicenseKey: 'YOUR_IOS_LICENSE_KEY',
    webLicenseKey: 'YOUR_WEB_LICENSE_KEY',
);
  1. The following methods in PspdfkitWidgetController have been deprecated in Nutrient Flutter SDK 4. Use the corresponding methods in PdfDocument instead:

  • setFormFieldValue — Use PdfDocument.setFormFieldValue.

  • getFormFieldValue — Use PdfDocument.getFormFieldValue.

  • applyInstantJson — Use PdfDocument.applyInstantJson.

  • exportInstantJson — Use PdfDocument.exportInstantJson.

  • addAnnotation — Use PdfDocument.addAnnotation.

  • removeAnnotation — Use PdfDocument.removeAnnotation.

  • getAnnotations — Use PdfDocument.getAnnotations.

  • getAllUnsavedAnnotations — Use PdfDocument.getAllUnsavedAnnotations.

  1. PspdfkitProcessor has been deprecated. The PspdfkitProcessor class methods can now be statically accessed from the Pspdfkit class.

Other API changes

Some APIs have been moved to new locations and renamed in Nutrient Flutter SDK 4. To ensure your project works correctly, update your code to use a single import statement for all Nutrient Flutter SDK classes and methods:

import 'package:pspdfkit_flutter/pspdfkit_flutter.dart';

Method channel backward compatibility

Nutrient Flutter SDK 4 introduces a new method channel API using Pigeon to bridge native APIs for iOS and Android. However, you can still use the old method channel APIs for backward compatibility. These will be removed in a future release.

To use the old method channel APIs, set the useLegacy parameter to true when initializing the SDK:

Pspdfkit.initialize(
    useLegacy: true,
);

Updating to Nutrient Flutter SDK 4

To update your project to use Nutrient Flutter SDK 4, follow the steps below.

  1. Update your pubspec.yaml file to use the latest version of the Nutrient Flutter SDK:

dependencies:
   pspdfkit_flutter: ^4.0.0

Changelog

For a complete list of changes in Nutrient Flutter SDK 4, see the changelog.