如何在Flutter中打开``URL启动器''之类的``csv文件'' [英] how to open a 'csv file' like 'url launcher' in Flutter
问题描述
清单2中未找到权限
,尝试 canLaunch 并以错误 name结束.csv通过Intent.getData()在应用程序之外公开,无法处理方法调用
那么如何在任何第三部分应用程序中打开该csv文件.
您可以在
下复制粘贴运行完整代码并确保您拥有文件/sdcard/Download/sample.csv
,请参见下面的图片
您还需要在模拟器中安装CSV查看器
代码段
最终文件路径='/sdcard/Download/sample.csv';print('$ {filePath}');最终消息=等待OpenFile.open(filePath);
工作演示
设备文件浏览器
完整代码
import'package:flutter/material.dart';导入'dart:async';导入'package:open_file/open_file.dart';void main()=>runApp(new MyApp());MyApp类扩展了StatefulWidget {@override_MyAppState createState()=>新的_MyAppState();}类别_MyAppState扩展了State< MyApp>{字符串_openResult ='未知';Future< void>openFile()异步{//最终的filePath ='/sdcard/Download/sample.pdf';最终的filePath ='/sdcard/Download/sample.csv';print('$ {filePath}');最终消息=等待OpenFile.open(filePath);setState((){_openResult =消息;});}@override窗口小部件build(BuildContext context){返回新的MaterialApp(主页:新脚手架(appBar:新的AppBar(标题:const Text('Plugin example app'),),身体:中心(子:列(mainAxisAlignment:MainAxisAlignment.center,子代:< Widget> [文字(打开结果:$ _ openResult \ n'),FlatButton(子级:Text(点按即可打开文件"),onPressed:openFile,),],),),),);}}
i converted list into File of .csv extension then
tried OpenFile.open and ended up with error No permissions found in manifest for: 2
, tried canLaunch and ended up with error name.csv exposed beyond app through Intent.getData(), Failed to handle method call
so how to open that csv file in any 3rd part application.
You can copy paste run full code below
and make sure you have a file /sdcard/Download/sample.csv
, see picture below
You also need CSV Viewer installed in your Emulator
code snippet
final filePath = '/sdcard/Download/sample.csv';
print('${filePath}');
final message = await OpenFile.open(filePath);
working demo
device file explorer
full code
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,
),
],
),
),
),
);
}
}
这篇关于如何在Flutter中打开``URL启动器''之类的``csv文件''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!