Language:
Serialization
PhotoEditor SDK for Flutter supports serialization and deserialization, allowing your users to save and revise their work at any time.
Enable Serialization#
To use the serialization feature, you first need to enable this option within the Configuration
.
Furthermore, you can select the export type of the serialization. For this example, we are retrieving the serialization as an object. However, you can also change this to be a local file URI.
Process Serialization data#
Once the editor has exported the photo successfully, the PhotoEditorResult
also contains a serialization
that you can further process.
The next section explains how to restore the editor state by deserializing these settings.
File:
import 'package:catalog/models/code_example.dart';import 'package:imgly_sdk/imgly_sdk.dart';import 'package:photo_editor_sdk/photo_editor_sdk.dart';class PhotoSerializationExample extends CodeExample {void invoke() async {// Create [SerializationOptions] to configure the serialization feature.final serializationOptions = SerializationOptions(// Enable the serialization feature.enabled: true,// For this example, the serialization should be returned// as an object to simply logging it in the console.exportType: SerializationExportType.object);// Create [ExportOptions] to apply the [serializationOptions].final exportOptions = ExportOptions(serialization: serializationOptions);// Create a [Configuration] instance.final configuration = Configuration(export: exportOptions);try {// Open the photo editor and handle the export as well as any occurring errors.final result = await PESDK.openEditor(image: "assets/LA.jpg", configuration: configuration);if (result != null) {// The user exported a new photo successfully and the newly generated photo is located at `result.image`// and the serialization is located at `result.serialization`.print(result.serialization);} else {// The user tapped on the cancel button within the editor.return;}} catch (error) {// There was an error generating the image.print(error);}}}