forked from PSPDFKit/pspdfkit-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_project_main.dart.txt
76 lines (63 loc) · 2.67 KB
/
demo_project_main.dart.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/// Copyright © 2021-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.
/// This is the main.dart code that should be copied into the demo project explained in `../README.md`.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:pspdfkit_flutter/src/main.dart';
const String DOCUMENT_PATH = 'PDFs/Document.pdf';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
initPlatformState();
}
void initPlatformState() async {
// By default, this example doesn't set a license key, but instead runs in trial mode (which is the default, and which requires no
// specific initialization). If you want to use a different license key for evaluation (e.g. a production license), you can uncomment
// the next line and set the license key.
//
// To set the license key for both platforms, use:
// await Pspdfkit.setLicenseKeys("YOUR_FLUTTER_ANDROID_LICENSE_KEY_GOES_HERE", "YOUR_FLUTTER_IOS_LICENSE_KEY_GOES_HERE");
//
// To set the license key for the currently running platform, use:
// await Pspdfkit.setLicenseKey("YOUR_FLUTTER_LICENSE_KEY_GOES_HERE");
}
void showDocument(BuildContext context) async {
final bytes = await DefaultAssetBundle.of(context).load(DOCUMENT_PATH);
final list = bytes.buffer.asUint8List();
final tempDir = await Pspdfkit.getTemporaryDirectory();
final tempDocumentPath = '${tempDir.path}/$DOCUMENT_PATH';
final file = await File(tempDocumentPath).create(recursive: true);
file.writeAsBytesSync(list);
await Pspdfkit.present(tempDocumentPath);
}
@override
Widget build(BuildContext context) {
final themeData = Theme.of(context);
return MaterialApp(
home: Scaffold(
body: Builder(
builder: (BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
child: Text('Tap to Open Document',
style: themeData.textTheme.headline4?.copyWith(fontSize: 21.0)),
onPressed: () => showDocument(context))
]));
},
)),
);
}
}