Improve PDF download on web
This commit is contained in:
parent
8dd8449ad5
commit
d1caa6efa6
|
|
@ -30,14 +30,14 @@ class _InvoiceViewHistoryState extends State<InvoiceViewHistory> {
|
|||
final viewModel = widget.viewModel;
|
||||
final invoice = viewModel.invoice;
|
||||
|
||||
final historyList = invoice.history.toList();
|
||||
historyList.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
|
||||
// TODO remove this null check, it shouldn't be needed
|
||||
if (invoice.isStale || invoice.history == null) {
|
||||
return LoadingIndicator();
|
||||
}
|
||||
|
||||
final historyList = invoice.history.toList();
|
||||
historyList.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
|
||||
return ListView.separated(
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
|
|
|
|||
|
|
@ -359,7 +359,7 @@ class ReportsScreenVM {
|
|||
'${state.uiState.reportsUIState.report}_report_$date.csv';
|
||||
|
||||
if (kIsWeb) {
|
||||
WebUtils.downloadFile(filename, csvData);
|
||||
WebUtils.downloadTextFile(filename, csvData);
|
||||
} else {
|
||||
final directory = await getExternalStorageDirectory();
|
||||
final filePath = '${directory.path}/$filename';
|
||||
|
|
|
|||
|
|
@ -137,9 +137,10 @@ class _PDFScaffoldState extends State<PDFScaffold> {
|
|||
onPressed: _response == null
|
||||
? null
|
||||
: () async {
|
||||
final fileName = '${invoice.number}.pdf';
|
||||
if (kIsWeb) {
|
||||
launch(invoice.invitationDownloadLink,
|
||||
forceSafariVC: false, forceWebView: false);
|
||||
WebUtils.downloadBinaryFile(
|
||||
fileName, _response.bodyBytes);
|
||||
} else {
|
||||
final directory = await getExternalStorageDirectory();
|
||||
final filePath =
|
||||
|
|
@ -147,7 +148,7 @@ class _PDFScaffoldState extends State<PDFScaffold> {
|
|||
final pdfData = file.File(filePath);
|
||||
pdfData.writeAsBytes(_response.bodyBytes);
|
||||
await FlutterShare.shareFile(
|
||||
title: 'test.pdf', filePath: filePath);
|
||||
title: fileName, filePath: filePath);
|
||||
}
|
||||
},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:html';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
||||
|
|
@ -27,13 +29,22 @@ class WebUtils {
|
|||
return completer.future;
|
||||
}
|
||||
|
||||
static void downloadFile(String filename, String data) {
|
||||
static void downloadTextFile(String filename, String data) {
|
||||
final encodedFileContents = Uri.encodeComponent(data);
|
||||
AnchorElement(href: 'data:text/plain;charset=utf-8,$encodedFileContents')
|
||||
..setAttribute('download', filename)
|
||||
..click();
|
||||
}
|
||||
|
||||
static void downloadBinaryFile(String filename, Uint8List data) {
|
||||
final encodedFileContents = base64Encode(data);
|
||||
AnchorElement(
|
||||
href:
|
||||
'data:application/octet-stream;charset=utf-16le;base64,$encodedFileContents')
|
||||
..setAttribute('download', filename)
|
||||
..click();
|
||||
}
|
||||
|
||||
static void reloadBrowser() => window.location.reload();
|
||||
|
||||
static void registerWebView(String html) {
|
||||
|
|
@ -54,7 +65,7 @@ class WebUtils {
|
|||
});
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
String loadToken() {
|
||||
final cookies = document.cookie;
|
||||
final List<String> listValues =
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
|
||||
|
|
@ -6,7 +8,9 @@ class WebUtils {
|
|||
|
||||
static Future<String> filePicker() => null;
|
||||
|
||||
static void downloadFile(String filename, String data) {}
|
||||
static void downloadTextFile(String filename, String data) {}
|
||||
|
||||
static void downloadBinaryFile(String filename, Uint8List data) {}
|
||||
|
||||
static void reloadBrowser() {}
|
||||
|
||||
|
|
@ -14,7 +18,7 @@ class WebUtils {
|
|||
|
||||
static void warnChanges(Store<AppState> store) {}
|
||||
|
||||
/*
|
||||
/*
|
||||
static String loadToken() => null;
|
||||
|
||||
static void saveToken(String token) {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue