TF-2754 Supports PDF viewing on Microsoft EDGE
This commit is contained in:
@@ -2,7 +2,6 @@ import 'dart:async';
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:core/data/constants/constant.dart';
|
|
||||||
import 'package:core/data/network/download/download_client.dart';
|
import 'package:core/data/network/download/download_client.dart';
|
||||||
import 'package:core/data/network/download/downloaded_response.dart';
|
import 'package:core/data/network/download/downloaded_response.dart';
|
||||||
import 'package:core/domain/exceptions/download_file_exception.dart';
|
import 'package:core/domain/exceptions/download_file_exception.dart';
|
||||||
@@ -117,17 +116,30 @@ class DownloadManager {
|
|||||||
try {
|
try {
|
||||||
fileName ??= 'unknown.pdf';
|
fileName ??= 'unknown.pdf';
|
||||||
final deviceInfo = await _deviceInfoPlugin.deviceInfo;
|
final deviceInfo = await _deviceInfoPlugin.deviceInfo;
|
||||||
if (mimeType != Constant.pdfMimeType
|
log('DownloadManager::openDownloadedFileWeb: TYPE = ${deviceInfo.runtimeType} | ${deviceInfo.data}');
|
||||||
|| '${deviceInfo.data['browserName']}' == 'BrowserName.firefox') {
|
if (deviceInfo is WebBrowserInfo) {
|
||||||
final blob = html.Blob([bytes], mimeType);
|
switch(deviceInfo.browserName) {
|
||||||
final file = html.File([blob], fileName, {'type': mimeType});
|
case BrowserName.chrome:
|
||||||
final url = html.Url.createObjectUrl(file);
|
case BrowserName.edge:
|
||||||
html.window.open(url, '_blank');
|
HtmlUtils.openNewTabHtmlDocument(HtmlUtils.chromePdfViewer(bytes, fileName));
|
||||||
html.Url.revokeObjectUrl(url);
|
break;
|
||||||
} else if ('${deviceInfo.data['browserName']}' == 'BrowserName.chrome') {
|
case BrowserName.safari:
|
||||||
HtmlUtils.openNewTabHtmlDocument(HtmlUtils.chromePdfViewer(bytes, fileName));
|
HtmlUtils.openNewTabHtmlDocument(HtmlUtils.safariPdfViewer(bytes, fileName));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
HtmlUtils.openFileViewer(
|
||||||
|
bytes: bytes,
|
||||||
|
fileName: fileName,
|
||||||
|
mimeType: mimeType
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
HtmlUtils.openNewTabHtmlDocument(HtmlUtils.safariPdfViewer(bytes, fileName));
|
HtmlUtils.openFileViewer(
|
||||||
|
bytes: bytes,
|
||||||
|
fileName: fileName,
|
||||||
|
mimeType: mimeType
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
logError('DownloadManager::openDownloadedFileWeb(): ERROR: $exception');
|
logError('DownloadManager::openDownloadedFileWeb(): ERROR: $exception');
|
||||||
|
|||||||
@@ -310,6 +310,18 @@ class HtmlUtils {
|
|||||||
</html>''';
|
</html>''';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void openFileViewer({
|
||||||
|
required Uint8List bytes,
|
||||||
|
required String fileName,
|
||||||
|
String? mimeType
|
||||||
|
}) {
|
||||||
|
final blob = html.Blob([bytes], mimeType);
|
||||||
|
final file = html.File([blob], fileName, {'type': mimeType});
|
||||||
|
final url = html.Url.createObjectUrl(file);
|
||||||
|
html.window.open(url, '_blank');
|
||||||
|
html.Url.revokeObjectUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
static const String _pdfContainerStyle = '''
|
static const String _pdfContainerStyle = '''
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -359,7 +371,7 @@ class HtmlUtils {
|
|||||||
<div id="app-bar">
|
<div id="app-bar">
|
||||||
<div id="file-info">
|
<div id="file-info">
|
||||||
<span id="file-name" style="margin-right: 10px;"></span>
|
<span id="file-name" style="margin-right: 10px;"></span>
|
||||||
(<span id="file-size", style="white-space: nowrap;"></span>)
|
(<span id="file-size" style="white-space: nowrap;"></span>)
|
||||||
</div>
|
</div>
|
||||||
<div style="width: 10px;"></div>
|
<div style="width: 10px;"></div>
|
||||||
<div id="buttons">
|
<div id="buttons">
|
||||||
|
|||||||
Reference in New Issue
Block a user