Created
April 3, 2020 12:51
-
-
Save VB10/a1171d616bf8ab16a0d4eb9d9f0cbb9e to your computer and use it in GitHub Desktop.
PDF View on Flutter Web
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:html' as html; | |
| import 'package:flutter/material.dart'; | |
| import 'dart:ui' as ui; | |
| import './pdf_web_view_view_model.dart'; | |
| class PdfWebViewView extends PdfWebViewViewModel { | |
| String samplePdf = "http://www.africau.edu/images/default/sample.pdf"; | |
| @override | |
| void initState() { | |
| super.initState(); | |
| registerView(pdfKey, "http://www.africau.edu/images/default/sample.pdf"); | |
| } | |
| Future<void> registerView(String key, String url) async { | |
| // ignore: undefined_prefixed_name | |
| await ui.platformViewRegistry.registerViewFactory( | |
| key, | |
| (int viewId) => html.IFrameElement() | |
| ..allowFullscreen = true | |
| ..src = '$url' | |
| ..style.border = 'none'); | |
| } | |
| String pdfKey = "key"; | |
| String pdfKey2 = "key2"; | |
| @override | |
| Widget build(BuildContext context) { | |
| // Replace this with your build function | |
| return Scaffold( | |
| appBar: AppBar( | |
| actions: <Widget>[ | |
| FloatingActionButton( | |
| onPressed: () async { | |
| pdfKey = 'veli'; | |
| await registerView('veli', | |
| "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"); | |
| setState(() {}); | |
| }, | |
| ) | |
| ], | |
| ), | |
| body: HtmlElementView(viewType: pdfKey), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment