如何在[Flutter]中打开PDF或Word文档 [英] How to open and PDF or word document in the [Flutter]

查看:5255
本文介绍了如何在[Flutter]中打开PDF或Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题很简单,我想使用Flutter通过默认应用打开任何pdf或doc文件.

Question is simple, I would like to open any pdf or doc file via default App with using Flutter.

请考虑一个与我的pdf资产相关的升高"按钮,当用户按下它时,将通过Acrobat Reader等打开pdf.我不想为此使用任何web_view.

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.

Flutter支持吗?

is it supported in Flutter?

推荐答案

您可以通过在网络浏览器中打开google文档来做到这一点:

You can do this by opening google docs in a web browser :

在pubspec.yaml中,您需要:

In pubspec.yaml you need :

url_launcher: ^0.4.2+5

包括:

import 'package:flutter/src/gestures/tap.dart';
import 'package:url_launcher/url_launcher.dart';

代码段:

new RichText(
  text: new LinkTextSpan(
      url: 'http://docs.google.com/viewer?url=http://www.pdf995.com/samples/pdf.pdf',
      text: 'Show My Pdf'),
),

LinkTextSpan类:

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

这篇关于如何在[Flutter]中打开PDF或Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆