Implement new PDF viewer
This commit is contained in:
parent
a3ff3496fa
commit
c10b201cf8
|
|
@ -1,73 +1,47 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/invoice_model.dart';
|
import 'package:invoiceninja_flutter/data/models/invoice_model.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
import 'package:invoiceninja_flutter/ui/app/loading_indicator.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
//import 'package:flutter_plugin_pdf_viewer/flutter_plugin_pdf_viewer.dart';
|
import 'package:flutter_pdfview/flutter_pdfview.dart';
|
||||||
|
|
||||||
Future<Null> viewPdf(InvoiceEntity invoice, BuildContext context) async {
|
Future<Null> viewPdf(InvoiceEntity invoice, BuildContext context) async {
|
||||||
/*
|
|
||||||
final navigator = Navigator.of(context);
|
|
||||||
navigator.push(
|
|
||||||
MaterialPageRoute<PDFViewer>(builder: (context) => PDFScreen(invoice)));
|
|
||||||
*/
|
|
||||||
|
|
||||||
final localization = AppLocalization.of(context);
|
showDialog<Scaffold>(
|
||||||
if (Theme.of(context).platform == TargetPlatform.iOS) {
|
context: context,
|
||||||
if (await canLaunch(invoice.invitationBorderlessLink)) {
|
builder: (BuildContext context) {
|
||||||
await launch(invoice.invitationBorderlessLink,
|
return Scaffold(
|
||||||
forceSafariVC: true, forceWebView: true);
|
appBar: AppBar(),
|
||||||
} else {
|
body: FutureBuilder(
|
||||||
throw localization.anErrorOccurred;
|
future: createFileOfPdfUrl(invoice.invitationDownloadLink),
|
||||||
}
|
builder: (BuildContext context, AsyncSnapshot<File> snapshot) {
|
||||||
} else {
|
switch (snapshot.connectionState) {
|
||||||
final String url =
|
case ConnectionState.none:
|
||||||
'https://docs.google.com/viewer?url=' + invoice.invitationDownloadLink;
|
case ConnectionState.active:
|
||||||
if (await canLaunch(url)) {
|
case ConnectionState.waiting:
|
||||||
await launch(url, forceSafariVC: false, forceWebView: false);
|
return LoadingIndicator();
|
||||||
} else {
|
case ConnectionState.done:
|
||||||
throw localization.anErrorOccurred;
|
if (snapshot.hasError)
|
||||||
}
|
return Text('Error: ${snapshot.error}');
|
||||||
}
|
else
|
||||||
|
return PDFView(filePath: snapshot.data.path);
|
||||||
|
}
|
||||||
|
return null; // unreachable
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
Future<File> createFileOfPdfUrl(String url) async {
|
||||||
class PDFScreen extends StatefulWidget {
|
final filename = url.substring(url.lastIndexOf('/') + 1);
|
||||||
const PDFScreen(this.invoice);
|
final request = await HttpClient().getUrl(Uri.parse(url));
|
||||||
|
final response = await request.close();
|
||||||
final InvoiceEntity invoice;
|
final bytes = await consolidateHttpClientResponseBytes(response);
|
||||||
|
final dir = (await getApplicationDocumentsDirectory()).path;
|
||||||
@override
|
final file = new File('$dir/$filename');
|
||||||
_PDFScreenState createState() => _PDFScreenState();
|
await file.writeAsBytes(bytes);
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PDFScreenState extends State<PDFScreen> {
|
|
||||||
PDFDocument document;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
|
|
||||||
PDFDocument.fromURL(widget.invoice.invitationDownloadLink).then((doc) {
|
|
||||||
setState(() => document = doc);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text('${widget.invoice.invoiceNumber}'),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: document == null
|
|
||||||
? CircularProgressIndicator()
|
|
||||||
: PDFViewer(
|
|
||||||
showPicker: false,
|
|
||||||
document: document,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,13 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
flutter_pdfview:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_pdfview
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.0+7"
|
||||||
flutter_redux:
|
flutter_redux:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,8 @@ dependencies:
|
||||||
local_auth: ^0.3.0
|
local_auth: ^0.3.0
|
||||||
sentry: ^2.2.0
|
sentry: ^2.2.0
|
||||||
image_picker: ^0.6.0+17
|
image_picker: ^0.6.0+17
|
||||||
#flutter_plugin_pdf_viewer: any
|
flutter_pdfview: ^1.0.0+7
|
||||||
#quick_actions: ^0.2.1
|
#quick_actions: ^0.2.1
|
||||||
#flutter_html_view: ^0.5.8
|
|
||||||
#flutter_html: ^0.5.3
|
|
||||||
#flutter_native_web: ^0.1.2
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_driver:
|
flutter_driver:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue