PDF support

This commit is contained in:
Hillel Coren 2019-12-26 21:40:59 +02:00
parent e1490c8aa1
commit 9d7ab7279f
5 changed files with 54 additions and 8 deletions

View File

@ -14,6 +14,7 @@ abstract class LocaleCodeAware {
mixin LocalizationsProvider on LocaleCodeAware {
static final Map<String, Map<String, String>> _localizedValues = {
'en': {
'pdf_min_requirements': 'The PDF renderer requires :version',
'adjust_fee_percent': 'Adjust Fee Percent',
'adjust_fee_percent_help': 'Ensure client fee matches the gateway fee',
'configure_settings': 'Configure Settings',
@ -15866,6 +15867,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
String get adjustFeePercentHelp => _localizedValues[localeCode]['adjust_fee_percent_help'];
String get pdfMinRequirements => _localizedValues[localeCode]['pdf_min_requirements'];
String lookup(String key) {
final lookupKey = toSnakeCase(key);
return _localizedValues[localeCode][lookupKey] ??

View File

@ -5,10 +5,11 @@ import 'package:invoiceninja_flutter/data/models/invoice_model.dart';
import 'package:flutter/foundation.dart';
import 'package:invoiceninja_flutter/ui/app/loading_indicator.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:invoiceninja_flutter/utils/platforms.dart';
import 'package:native_pdf_view/native_pdf_view.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);
if (Platform.isIOS) {
@ -56,7 +57,8 @@ Future<Null> viewPdf(InvoiceEntity invoice, BuildContext context) async {
return LoadingIndicator();
case ConnectionState.done:
if (snapshot.hasError)
return Text('Error: ${snapshot.error}');
return Text(
'${getPdfRequirements(context)} - Error: ${snapshot.error}');
else
return snapshot.data.length == 1
? Center(
@ -80,10 +82,11 @@ Future<Null> viewPdf(InvoiceEntity invoice, BuildContext context) async {
),
Container(
color: Colors.white,
child: Image(
image:
MemoryImage(page.bytes),
height: double.infinity),
child: ExtendedImage.memory(
page.bytes,
fit: BoxFit.fitHeight,
mode: ExtendedImageMode.gesture,
),
),
],
))

View File

@ -3,6 +3,7 @@ import 'package:flutter_redux/flutter_redux.dart';
import 'package:invoiceninja_flutter/constants.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/redux/ui/pref_state.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
bool isAndroid(BuildContext context) =>
Theme.of(context).platform == TargetPlatform.android;
@ -15,6 +16,16 @@ String getLegacyAppURL(BuildContext context) => isAndroid(context)
? 'https://play.google.com/store/apps/details?id=com.invoiceninja.invoiceninja'
: 'https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=1220337560&mt=8';
String getPdfRequirements(BuildContext context) {
final localization = AppLocalization.of(context);
if (isMobile(context)) {
final version = isAndroid(context) ? 'Android 5.0+' : 'iOS 11.0+';
return localization.pdfMinRequirements.replaceFirst(':version', version);
} else {
return '';
}
}
String getPlatform(BuildContext context) =>
Theme.of(context).platform == TargetPlatform.iOS ? 'ios' : 'android';

View File

@ -190,6 +190,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.3"
extended_image:
dependency: transitive
description:
name: extended_image
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.8"
extended_image_library:
dependency: transitive
description:
name: extended_image_library
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.9"
extension:
dependency: transitive
description:
@ -395,6 +409,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.0+2"
http_client_helper:
dependency: transitive
description:
name: http_client_helper
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.1"
http_multi_server:
dependency: transitive
description:
@ -522,12 +543,19 @@ packages:
source: hosted
version: "1.0.2"
native_pdf_renderer:
dependency: "direct main"
dependency: transitive
description:
name: native_pdf_renderer
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.1"
native_pdf_view:
dependency: "direct main"
description:
name: native_pdf_view
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
node_interop:
dependency: transitive
description:

View File

@ -40,7 +40,8 @@ dependencies:
flutter_json_widget: ^1.0.2
webview_flutter: ^0.3.15+1
timeago: ^2.0.22
native_pdf_renderer: any
#native_pdf_renderer: any
native_pdf_view: any
flutter_typeahead: ^1.7.0
#quick_actions: ^0.2.1