I want to view file like pdf,doc,pptx and etc in my flutter app using url and I don't want to store any file in device

huangapple go评论64阅读模式
英文:

I want to view file like pdf,doc,pptx and etc in my flutter app using url and I don't want to store any file in device

问题

我想在我的Flutter应用中使用URL查看PDF、DOC、PPTX等文件,而且我不想在设备上存储任何文件。

英文:

I want to view file like pdf,doc,pptx and etc in my flutter app using url and I don't want to store any file in device

答案1

得分: 2

您可以使用flutter_webview_plugin包在Flutter应用中显示文件,而无需下载或存储它们在设备上。以下是如何使用它来显示PDF文件的示例:

将flutter_webview_plugin包添加到您的pubspec.yaml文件中,并运行flutter pub get来安装它。

在您的Dart代码中导入该包:

import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

使用WebviewScaffold小部件来显示PDF文件:

WebviewScaffold(
  url: 'https://example.com/path/to/file.pdf',
  withZoom: true,
  withLocalStorage: true,
);

url参数应指向您要显示的PDF文件的URL。withZoom和withLocalStorage参数是可选的,它们控制用户是否可以放大和缩小文件以及是否使用本地存储进行缓存。

您可以使用相同的方法来显示其他类型的文件,例如Microsoft Office文档和PowerPoint演示文稿,只要文件可以通过URL访问即可。

英文:

You can use the flutter_webview_plugin package to display files in your Flutter app without downloading or storing them on the device. Here is an example of how to use it to display PDF files:

Add the flutter_webview_plugin package to your pubspec.yaml file and run flutter pub get to install it.

Import the package in your Dart code:

import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

Use the WebviewScaffold widget to display the PDF file:

WebviewScaffold(
url: 'https://example.com/path/to/file.pdf',
withZoom: true,
withLocalStorage: true,
);

The url parameter should point to the URL of the PDF file you want to display. The withZoom and withLocalStorage parameters are optional and control whether the user can zoom in and out of the file and whether any local storage is used for caching.

You can use the same approach to display other types of files, such as Microsoft Office documents and PowerPoint presentations, as long as the file is accessible via a URL.

huangapple
  • 本文由 发表于 2023年2月18日 02:24:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75488024.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定