【发布时间】:2020-02-12 14:03:47
【问题描述】:
如果我点击文件,如何在 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 在应用程序中打开该文件。
【问题讨论】:
-
在应用程序中打开文件需要大量代码才能处理所有格式,强烈建议使用专用应用程序,您可以使用:pub.dev/packages/open_file
-
我使用了 open_file 包,但它不起作用——这是我在 onTap 上完成的代码:() async { String fileUrl = widget.schoolDcUrl + "/container" + attachments[index];字符串 fileUrl1 = Uri.encodeFull(fileUrl); final _openFile = 等待 OpenFile.open(fileUrl);记录器.i(_openFile); }
-
这是完美的答案stackoverflow.com/a/60203399/15601357,没有任何样板