You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.6 KiB
Dart
49 lines
1.6 KiB
Dart
import 'dart:typed_data';
|
|
import 'dart:ui' as ui;
|
|
import 'package:flutter/material.dart';
|
|
// ignore: avoid_web_libraries_in_flutter
|
|
import 'dart:html' as html;
|
|
|
|
Future<void> platformViewPdf(BuildContext context, Uint8List bytes, {required String filename}) async {
|
|
final blob = html.Blob([bytes], 'application/pdf');
|
|
final url = html.Url.createObjectUrlFromBlob(blob);
|
|
final viewType = 'pdf-view-${DateTime.now().microsecondsSinceEpoch}';
|
|
final iframe = html.IFrameElement()
|
|
..src = url
|
|
..style.border = '0'
|
|
..style.width = '100%'
|
|
..style.height = '100%';
|
|
// ignore: undefined_prefixed_name
|
|
ui.platformViewRegistry.registerViewFactory(viewType, (int _) => iframe);
|
|
|
|
await showDialog<void>(
|
|
context: context,
|
|
builder: (ctx) => Dialog(
|
|
insetPadding: const EdgeInsets.all(16),
|
|
child: SizedBox(
|
|
width: 1000, height: 700,
|
|
child: Stack(children: [
|
|
HtmlElementView(viewType: viewType),
|
|
Positioned(
|
|
right: 8, top: 8,
|
|
child: IconButton(
|
|
tooltip: 'In neuem Tab öffnen',
|
|
icon: const Icon(Icons.open_in_new),
|
|
onPressed: () => html.window.open(url, '_blank'),
|
|
),
|
|
),
|
|
]),
|
|
),
|
|
),
|
|
);
|
|
html.Url.revokeObjectUrl(url);
|
|
}
|
|
|
|
Future<void> platformDownloadPdf(Uint8List bytes, {required String filename}) async {
|
|
final blob = html.Blob([bytes], 'application/pdf');
|
|
final url = html.Url.createObjectUrlFromBlob(blob);
|
|
final a = html.AnchorElement(href: url)..download = filename;
|
|
a.click();
|
|
html.Url.revokeObjectUrl(url);
|
|
}
|