如果我单击文件,如何在flutter应用程序中打开该文件。
这是我所做的:
该代码用于show在listView中运行:
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: attachments.length,
itemBuilder: (BuildContext ctxt, int index) {
print (index);
return ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(1.0),
child: ListTile(
leading: CircleAvatar(
child: _getIcon(
attachments[index].split('/').removeLast()),
backgroundColor: Colors.white,
),
subtitle:
Text(attachments[index].split('/').removeLast()),
onTap: (){}
),
),
]);
})
我使用过open_file包,但是它不起作用,这是我做过的代码:
onTap: () async {
String fileUrl = widget.schoolDcUrl + "/container"attachments[index];
final _openFile = await OpenFile.open(fileUrl);
Logger.i(_openFile);
}
当我单击文件时,它不会打开文件,它将在未找到的终端文件上显示一条消息。
我希望onTap在应用程序中打开该文件。
最佳答案
在pubspec.yaml
中添加:
dev_dependencies:
open_file: ^3.0.1
在代码中添加:import 'package:open_file/open_file.dart';
OpenFile.open("/sdcard/example.pptx");
open_file
文档:https://pub.dev/packages/open_file#-readme-tab-
关于flutter - 如何在Flutter应用中打开pdf,pptx,doc,docx文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60190124/