Question is simple, I would like to open any pdf or doc file via default App with using Flutter.
Think a Raised button that related my pdf asset, when user press it, pdf will be opened via Acrobat reader or etc. I don't want to use any web_view for it.
is it supported in Flutter?
The Syncfusion Flutter PDF Viewer widget provides the support to load a PDF document from Asset, Network, File, and Memory. The SfPdfViewer.network is used to load a PDF document from a URL, which creates a widget that displays the PDF document obtained from the provided URL.
You can do this by opening google docs in a web browser :
In pubspec.yaml you need :
url_launcher: ^0.4.2+5
Includes :
import 'package:flutter/src/gestures/tap.dart'; import 'package:url_launcher/url_launcher.dart';
Code snippet :
new RichText( text: new LinkTextSpan( url: 'http://docs.google.com/viewer?url=http://www.pdf995.com/samples/pdf.pdf', text: 'Show My Pdf'), ),
LinkTextSpan class :
class LinkTextSpan extends TextSpan { LinkTextSpan({TextStyle style, String url, String text}) : super( style: style, text: text ?? url, recognizer: new TapGestureRecognizer() ..onTap = () { launch(url); }); }
A good and simple approach to this is the open_file package which lets you open a file with the given path. It supports numerous different file types:
import 'package:open_file/open_file.dart'; OpenFile.open("/sdcard/example.pdf");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With