Update PDF
This commit is contained in:
parent
bda512d863
commit
347a1ac605
|
|
@ -42,7 +42,7 @@ android {
|
|||
|
||||
defaultConfig {
|
||||
applicationId "com.invoiceninja.client"
|
||||
minSdkVersion 16
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 28
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ android {
|
|||
|
||||
defaultConfig {
|
||||
applicationId "com.invoiceninja.client"
|
||||
minSdkVersion 16
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 28
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
|
|
|
|||
|
|
@ -209,7 +209,9 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
|
|||
//showPerformanceOverlay: true,
|
||||
localizationsDelegates: [
|
||||
const AppLocalizationsDelegate(),
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate
|
||||
],
|
||||
home: state.uiState.requireAuthentication && !_authenticated
|
||||
? Material(
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/resources/cached_image.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/upgrade_dialog.dart';
|
||||
import 'package:invoiceninja_flutter/utils/pdf.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:invoiceninja_flutter/constants.dart';
|
||||
|
|
@ -475,6 +476,8 @@ class SidebarFooter extends StatelessWidget {
|
|||
Icons.warning,
|
||||
color: Colors.red,
|
||||
),
|
||||
onPressed: () => viewPdf(InvoiceEntity(), context),
|
||||
/*
|
||||
onPressed: () => showDialog<ErrorDialog>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
|
|
@ -483,6 +486,7 @@ class SidebarFooter extends StatelessWidget {
|
|||
clearErrorOnDismiss: true,
|
||||
);
|
||||
}),
|
||||
*/
|
||||
),
|
||||
if (!Platform.isIOS &&
|
||||
isHosted(context) &&
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/invoice_model.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/loading_indicator.dart';
|
||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:flutter_pdfview/flutter_pdfview.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:native_pdf_renderer/native_pdf_renderer.dart';
|
||||
|
||||
Future<Null> viewPdf(InvoiceEntity invoice, BuildContext context) async {
|
||||
final localization = AppLocalization.of(context);
|
||||
|
|
@ -46,7 +47,8 @@ Future<Null> viewPdf(InvoiceEntity invoice, BuildContext context) async {
|
|||
),
|
||||
body: FutureBuilder(
|
||||
future: createFileOfPdfUrl(invoice.invitationDownloadLink),
|
||||
builder: (BuildContext context, AsyncSnapshot<File> snapshot) {
|
||||
builder:
|
||||
(BuildContext context, AsyncSnapshot<PDFPageImage> snapshot) {
|
||||
switch (snapshot.connectionState) {
|
||||
case ConnectionState.none:
|
||||
case ConnectionState.active:
|
||||
|
|
@ -56,7 +58,14 @@ Future<Null> viewPdf(InvoiceEntity invoice, BuildContext context) async {
|
|||
if (snapshot.hasError)
|
||||
return Text('Error: ${snapshot.error}');
|
||||
else
|
||||
return PDFView(filePath: snapshot.data.path);
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
width: double.infinity,
|
||||
child: Image(
|
||||
height: double.infinity,
|
||||
image: MemoryImage(snapshot.data.bytes),
|
||||
),
|
||||
);
|
||||
}
|
||||
return null; // unreachable
|
||||
}),
|
||||
|
|
@ -64,13 +73,27 @@ Future<Null> viewPdf(InvoiceEntity invoice, BuildContext context) async {
|
|||
});
|
||||
}
|
||||
|
||||
Future<File> createFileOfPdfUrl(String url) async {
|
||||
Future<PDFPageImage> createFileOfPdfUrl(String url) async {
|
||||
final filename = url.substring(url.lastIndexOf('/') + 1);
|
||||
|
||||
url =
|
||||
'https://staging.invoiceninja.com/download/gj5d2udwzowatfsjibarq4eyo4k0cvpd';
|
||||
|
||||
final request = await HttpClient().getUrl(Uri.parse(url));
|
||||
final response = await request.close();
|
||||
final bytes = await consolidateHttpClientResponseBytes(response);
|
||||
|
||||
final document = await PDFDocument.openData(bytes);
|
||||
final page = await document.getPage(1);
|
||||
final pageImage = await page.render(width: page.width, height: page.height);
|
||||
await page.close();
|
||||
|
||||
return pageImage;
|
||||
|
||||
/*
|
||||
final dir = (await getApplicationDocumentsDirectory()).path;
|
||||
final file = new File('$dir/$filename');
|
||||
await file.writeAsBytes(bytes);
|
||||
return file;
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
21
pubspec.lock
21
pubspec.lock
|
|
@ -176,6 +176,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.9"
|
||||
extension:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: extension
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.5"
|
||||
faker:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
|
@ -233,13 +240,6 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_pdfview:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_pdfview
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0+9"
|
||||
flutter_redux:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
@ -432,6 +432,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
native_pdf_renderer:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: native_pdf_renderer
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.5.0"
|
||||
node_preamble:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
name: invoiceninja_flutter
|
||||
description: Mobile app for Invoice Ninja
|
||||
description: Client for Invoice Ninja
|
||||
version: 2.0.0+0
|
||||
author: Hillel Coren
|
||||
homepage: https://www.invoiceninja.com
|
||||
|
|
@ -34,7 +34,7 @@ dependencies:
|
|||
local_auth: ^0.5.2+4
|
||||
sentry: ^2.2.0
|
||||
image_picker: ^0.6.1+4
|
||||
flutter_pdfview: ^1.0.0+9
|
||||
native_pdf_renderer: any
|
||||
#quick_actions: ^0.2.1
|
||||
|
||||
dev_dependencies:
|
||||
|
|
|
|||
Loading…
Reference in New Issue