How to open and PDF or word document in the [Flutter] How to open and PDF or word document in the [Flutter] flutter flutter

How to open and PDF or word document in the [Flutter]


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");


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);        });}


You can use url_launcher package for this. Just pass the path of your document to the launch() method as the parameter.