我要解决这个问题----如果我单击PDF,Doc,PPTX,Docx文件,那么如何为打开该文件提供多种选择。如何在WPS Office等构建应用程序中的手机中打开该文件。
This is my code to show files in 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: (){}
),
),
]);
})
现在点击文件时如何在手机WPS Office应用中打开该文件。
您可以使用软件包https://pub.dev/packages/open_file您可以在下面复制粘贴运行完整代码,并需要将文件放入/sdcard/Download/sample.csv
中进行测试该软件包将为您显示可用选项
工作演示
完整代码
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:open_file/open_file.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _openResult = 'Unknown';
Future<void> openFile() async {
//final filePath = '/sdcard/Download/sample.pdf';
final filePath = '/sdcard/Download/sample.csv';
print('${filePath}');
final message = await OpenFile.open(filePath);
setState(() {
_openResult = message;
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('open result: $_openResult\n'),
FlatButton(
child: Text('Tap to open file'),
onPressed: openFile,
),
],
),
),
),
);
}
}