@@ -12,6 +12,7 @@ import 'dart:async';
1212import 'package:flutter/cupertino.dart' ;
1313import 'package:flutter/material.dart' ;
1414import 'package:flutter/services.dart' ;
15+ import 'package:pspdfkit_example/pspdfkit_save_as_example.dart' ;
1516
1617import 'package:pspdfkit_flutter/src/main.dart' ;
1718import 'package:pspdfkit_flutter/src/widgets/pspdfkit_widget_controller.dart' ;
@@ -21,7 +22,9 @@ import 'pspdfkit_form_example.dart';
2122import 'pspdfkit_instantjson_example.dart' ;
2223import 'pspdfkit_annotations_example.dart' ;
2324import 'pspdfkit_manual_save_example.dart' ;
25+ import 'pspdfkit_save_as_example.dart' ;
2426import 'pspdfkit_annotation_processing_example.dart' ;
27+ import 'platform_utils.dart' ;
2528
2629const String _documentPath = 'PDFs/PSPDFKit.pdf' ;
2730const String _lockedDocumentPath = 'PDFs/protected.pdf' ;
@@ -59,8 +62,11 @@ const String _annotationsExample =
5962const String _annotationsExampleSub =
6063 'Programmatically adds and removes annotations using a custom Widget.' ;
6164const String _manualSaveExample = 'Manual Save' ;
65+ const String _saveAsExample = 'Save As' ;
6266const String _manualSaveExampleSub =
6367 'Add a save button at the bottom and disable automatic saving.' ;
68+ const String _saveAsExampleSub =
69+ 'Embed and save the changes made to a document into a new file' ;
6470const String _annotationProcessingExample = 'Process Annotations' ;
6571const String _annotationProcessingExampleSub =
6672 'Programmatically adds and removes annotations using a custom Widget.' ;
@@ -145,31 +151,18 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
145151 return file;
146152 }
147153
148- bool isCupertino (BuildContext context) {
149- final defaultTargetPlatform = Theme .of (context).platform;
150- switch (defaultTargetPlatform) {
151- case TargetPlatform .iOS:
152- case TargetPlatform .macOS:
153- return true ;
154- case TargetPlatform .android:
155- case TargetPlatform .fuchsia:
156- case TargetPlatform .linux:
157- case TargetPlatform .windows:
158- return false ;
159- }
160- }
161-
162154 void showDocument () async {
163155 final extractedDocument = await extractAsset (_documentPath);
164156 await Navigator .of (context).push <dynamic >(MaterialPageRoute <dynamic >(
165157 builder: (_) => Scaffold (
166- extendBodyBehindAppBar: isCupertino (context) ? false : true ,
158+ extendBodyBehindAppBar:
159+ PlatformUtils .isCupertino (context) ? false : true ,
167160 appBar: AppBar (),
168161 body: SafeArea (
169162 top: false ,
170163 bottom: false ,
171164 child: Container (
172- padding: isCupertino (context)
165+ padding: PlatformUtils . isCupertino (context)
173166 ? null
174167 : const EdgeInsets .only (top: kToolbarHeight),
175168 child: PspdfkitWidget (
@@ -179,7 +172,7 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
179172 void showDocumentPlatformStyle () async {
180173 final extractedDocument = await extractAsset (_documentPath);
181174
182- if (isCupertino (context)) {
175+ if (PlatformUtils . isCupertino (context)) {
183176 await Navigator .of (context).push <dynamic >(CupertinoPageRoute <dynamic >(
184177 builder: (_) => CupertinoPageScaffold (
185178 navigationBar: const CupertinoNavigationBar (),
@@ -206,13 +199,14 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
206199 final extractedImage = await extractAsset (_imagePath);
207200 await Navigator .of (context).push <dynamic >(MaterialPageRoute <dynamic >(
208201 builder: (_) => Scaffold (
209- extendBodyBehindAppBar: isCupertino (context) ? false : true ,
202+ extendBodyBehindAppBar:
203+ PlatformUtils .isCupertino (context) ? false : true ,
210204 appBar: AppBar (),
211205 body: SafeArea (
212206 top: false ,
213207 bottom: false ,
214208 child: Container (
215- padding: isCupertino (context)
209+ padding: PlatformUtils . isCupertino (context)
216210 ? null
217211 : const EdgeInsets .only (top: kToolbarHeight),
218212 child:
@@ -223,13 +217,14 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
223217 final extractedDocument = await extractAsset (_documentPath);
224218 await Navigator .of (context).push <dynamic >(MaterialPageRoute <dynamic >(
225219 builder: (_) => Scaffold (
226- extendBodyBehindAppBar: isCupertino (context) ? false : true ,
220+ extendBodyBehindAppBar:
221+ PlatformUtils .isCupertino (context) ? false : true ,
227222 appBar: AppBar (),
228223 body: SafeArea (
229224 top: false ,
230225 bottom: false ,
231226 child: Container (
232- padding: isCupertino (context)
227+ padding: PlatformUtils . isCupertino (context)
233228 ? null
234229 : const EdgeInsets .only (top: kToolbarHeight),
235230 child: PspdfkitWidget (
@@ -245,13 +240,14 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
245240 final extractedDocument = await extractAsset (_documentPath);
246241 await Navigator .of (context).push <dynamic >(MaterialPageRoute <dynamic >(
247242 builder: (_) => Scaffold (
248- extendBodyBehindAppBar: isCupertino (context) ? false : true ,
243+ extendBodyBehindAppBar:
244+ PlatformUtils .isCupertino (context) ? false : true ,
249245 appBar: AppBar (),
250246 body: SafeArea (
251247 top: false ,
252248 bottom: false ,
253249 child: Container (
254- padding: isCupertino (context)
250+ padding: PlatformUtils . isCupertino (context)
255251 ? null
256252 : const EdgeInsets .only (top: kToolbarHeight),
257253 child: PspdfkitWidget (
@@ -312,13 +308,14 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
312308 final extractedLockedDocument = await extractAsset (_lockedDocumentPath);
313309 await Navigator .of (context).push <dynamic >(MaterialPageRoute <dynamic >(
314310 builder: (_) => Scaffold (
315- extendBodyBehindAppBar: isCupertino (context) ? false : true ,
311+ extendBodyBehindAppBar:
312+ PlatformUtils .isCupertino (context) ? false : true ,
316313 appBar: AppBar (),
317314 body: SafeArea (
318315 top: false ,
319316 bottom: false ,
320317 child: Container (
321- padding: isCupertino (context)
318+ padding: PlatformUtils . isCupertino (context)
322319 ? null
323320 : const EdgeInsets .only (top: kToolbarHeight),
324321 child: PspdfkitWidget (
@@ -350,8 +347,8 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
350347 }
351348
352349 void manualSaveExample () async {
353- final extractedWritableDocument =
354- await extractAsset (_documentPath, shouldOverwrite: false , prefix: 'persist' );
350+ final extractedWritableDocument = await extractAsset (_documentPath,
351+ shouldOverwrite: false , prefix: 'persist' );
355352
356353 // Automatic Saving of documents is enabled by default in certain scenarios [see for details: https://pspdfkit.com/guides/flutter/save-a-document/#auto-save]
357354 // In order to manually save documents, you might consider disabling automatic saving with disableAutosave: true in the config
@@ -361,6 +358,18 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
361358 configuration: const {disableAutosave: true })));
362359 }
363360
361+ void saveAsExample () async {
362+ final extractedWritableDocument = await extractAsset (_documentPath,
363+ shouldOverwrite: false , prefix: 'persist' );
364+
365+ // Automatic Saving of documents is enabled by default in certain scenarios [see for details: https://pspdfkit.com/guides/flutter/save-a-document/#auto-save]
366+ // In order to manually save documents, you might consider disabling automatic saving with disableAutosave: true in the config
367+ await Navigator .of (context).push <dynamic >(MaterialPageRoute <dynamic >(
368+ builder: (_) => PspdfkitSaveAsExampleWidget (
369+ documentPath: extractedWritableDocument.path,
370+ configuration: const {disableAutosave: true })));
371+ }
372+
364373 void annotationProcessingExample () async {
365374 final extractedDocument = await extractAsset (_documentPath);
366375 await Navigator .of (context).push <dynamic >(MaterialPageRoute <dynamic >(
@@ -374,7 +383,7 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
374383 final extractedDocument = await extractAsset (_documentPath);
375384 final extractedFormDocument = await extractAsset (_formPath);
376385
377- if (isCupertino (context)) {
386+ if (PlatformUtils . isCupertino (context)) {
378387 await Navigator .of (context).push <dynamic >(CupertinoPageRoute <dynamic >(
379388 builder: (_) => CupertinoPageScaffold (
380389 navigationBar: CupertinoNavigationBar (),
@@ -669,20 +678,25 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
669678 title: const Text (_manualSaveExample),
670679 subtitle: const Text (_manualSaveExampleSub),
671680 onTap: () => manualSaveExample ()),
681+ if (PlatformUtils .isCupertino (context))
682+ ListTile (
683+ title: const Text (_saveAsExample),
684+ subtitle: const Text (_saveAsExampleSub),
685+ onTap: () => saveAsExample ()),
672686 // The annotation processing example is supported by iOS only for now.
673- if (isCupertino (context))
687+ if (PlatformUtils . isCupertino (context))
674688 ListTile (
675689 title: const Text (_annotationProcessingExample),
676690 subtitle: const Text (_annotationProcessingExampleSub),
677691 onTap: () => annotationProcessingExample ()),
678692 // The import Instant JSON example is supported by iOS only for now.
679- if (isCupertino (context))
693+ if (PlatformUtils . isCupertino (context))
680694 ListTile (
681695 title: const Text (_importInstantJsonExample),
682696 subtitle: const Text (_importInstantJsonExampleSub),
683697 onTap: () => importInstantJsonExample ()),
684698 // The push two PspdfWidgets simultaneously example is supported by iOS only for now.
685- if (isCupertino (context))
699+ if (PlatformUtils . isCupertino (context))
686700 ListTile (
687701 title: const Text (_widgetExampleFullScreen),
688702 subtitle: const Text (_widgetExampleFullScreenSub),
0 commit comments