-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
PSPDFKit
committed
Feb 22, 2022
1 parent
3519803
commit d09a6ae
Showing
16 changed files
with
217 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:flutter/foundation.dart'; | ||
|
||
class PlatformUtils { | ||
static bool isCurrentPlatformSupported() { | ||
return defaultTargetPlatform == TargetPlatform.android || | ||
defaultTargetPlatform == TargetPlatform.iOS; | ||
} | ||
|
||
static bool isAndroid() { | ||
return defaultTargetPlatform == TargetPlatform.android; | ||
} | ||
|
||
static bool isIOS() { | ||
return defaultTargetPlatform == TargetPlatform.iOS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/// | ||
/// Copyright © 2022 PSPDFKit GmbH. All rights reserved. | ||
/// | ||
/// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW | ||
/// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT. | ||
/// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES. | ||
/// This notice may not be removed from this file. | ||
/// | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/gestures.dart'; | ||
import 'package:flutter/rendering.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:pspdfkit_flutter/src/widgets/pspdfkit_widget_controller.dart'; | ||
|
||
import 'platform_utils.dart'; | ||
|
||
class PspdfkitManualSaveExampleWidget extends StatefulWidget { | ||
final String documentPath; | ||
final dynamic configuration; | ||
|
||
const PspdfkitManualSaveExampleWidget( | ||
{Key? key, required this.documentPath, this.configuration}) | ||
: super(key: key); | ||
|
||
@override | ||
_PspdfkitManualSaveExampleWidgetState createState() => | ||
_PspdfkitManualSaveExampleWidgetState(); | ||
} | ||
|
||
class _PspdfkitManualSaveExampleWidgetState | ||
extends State<PspdfkitManualSaveExampleWidget> { | ||
late PspdfkitWidgetController pspdfkitWidgetController; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
// This is used in the platform side to register the view. | ||
const String viewType = 'com.pspdfkit.widget'; | ||
// Pass parameters to the platform side. | ||
final Map<String, dynamic> creationParams = <String, dynamic>{ | ||
'document': widget.documentPath, | ||
'configuration': widget.configuration | ||
}; | ||
if (PlatformUtils.isCurrentPlatformSupported()) { | ||
return Scaffold( | ||
extendBodyBehindAppBar: | ||
defaultTargetPlatform == TargetPlatform.android, | ||
appBar: AppBar(), | ||
body: SafeArea( | ||
top: false, | ||
bottom: false, | ||
child: Container( | ||
padding: defaultTargetPlatform == TargetPlatform.iOS | ||
? null | ||
: const EdgeInsets.only(top: kToolbarHeight), | ||
child: Column(children: <Widget>[ | ||
Expanded( | ||
child: PlatformUtils.isAndroid() | ||
? PlatformViewLink( | ||
viewType: viewType, | ||
surfaceFactory: (BuildContext context, | ||
PlatformViewController controller) { | ||
return AndroidViewSurface( | ||
controller: | ||
controller as AndroidViewController, | ||
gestureRecognizers: const < | ||
Factory< | ||
OneSequenceGestureRecognizer>>{}, | ||
hitTestBehavior: | ||
PlatformViewHitTestBehavior.opaque, | ||
); | ||
}, | ||
onCreatePlatformView: | ||
(PlatformViewCreationParams params) { | ||
return PlatformViewsService | ||
.initSurfaceAndroidView( | ||
id: params.id, | ||
viewType: viewType, | ||
layoutDirection: TextDirection.ltr, | ||
creationParams: creationParams, | ||
creationParamsCodec: | ||
const StandardMessageCodec(), | ||
onFocus: () { | ||
params.onFocusChanged(true); | ||
}, | ||
) | ||
..addOnPlatformViewCreatedListener( | ||
params.onPlatformViewCreated) | ||
..addOnPlatformViewCreatedListener( | ||
onPlatformViewCreated) | ||
..create(); | ||
}) | ||
: UiKitView( | ||
viewType: viewType, | ||
layoutDirection: TextDirection.ltr, | ||
creationParams: creationParams, | ||
onPlatformViewCreated: onPlatformViewCreated, | ||
creationParamsCodec: | ||
const StandardMessageCodec())), | ||
SizedBox( | ||
child: Column(children: <Widget>[ | ||
ElevatedButton( | ||
onPressed: () async { | ||
await pspdfkitWidgetController.save(); | ||
}, | ||
child: const Text('Save Document')) | ||
])) | ||
])))); | ||
} else { | ||
return Text( | ||
'$defaultTargetPlatform is not yet supported by PSPDFKit for Flutter.'); | ||
} | ||
} | ||
|
||
Future<void> onPlatformViewCreated(int id) async { | ||
pspdfkitWidgetController = PspdfkitWidgetController(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.