-
Notifications
You must be signed in to change notification settings - Fork 58
/
demo_project_main.dart.txt
74 lines (66 loc) · 2.73 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
/// Copyright © 2021-2024 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/foundation.dart';
import 'package:flutter/material.dart';
import 'package:pspdfkit_flutter/pspdfkit.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");
}
Future<String> extractAsset(BuildContext context, String assetPath) async {
if (kIsWeb) {
return assetPath;
}
final bytes = await DefaultAssetBundle.of(context).load(assetPath);
final list = bytes.buffer.asUint8List();
final tempDir = await Pspdfkit.getTemporaryDirectory();
final tempDocumentPath = '${tempDir.path}/$assetPath';
final file = File(tempDocumentPath);
await file.create(recursive: true);
file.writeAsBytesSync(list);
return file.path;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: FutureBuilder<String>(
future: extractAsset(context, DOCUMENT_PATH),
builder: (context, snapshot) {
if (snapshot.hasData) {
/// PspdfkitWidget is a widget that displays a PDF document.
return PspdfkitWidget(
documentPath: snapshot.data!,
);
} else {
return const Center(child: CircularProgressIndicator());
}
})),
);
}
}