如何在 Flutter 中打开像 'url launcher' 这样的 'csv file'

how to open a 'csv file' like 'url launcher' in Flutter

然后我将列表转换为.csv扩展名的文件 尝试了 OpenFile.open 并以错误 No permissions found in manifest for: 2 结束,尝试了 canLaunch 并以错误 name.csv exposed beyond app through Intent.getData(), Failed to handle method call[ 结束=14=]

那么如何在任何第 3 部分应用程序中打开该 csv 文件。

您可以复制粘贴 运行 下面的完整代码
并确保你有一个文件 /sdcard/Download/sample.csv,见下图
您还需要在模拟器中安装 CSV 查看器
代码片段

    final filePath = '/sdcard/Download/sample.csv';
    print('${filePath}');
    final message = await OpenFile.open(filePath);

工作演示

设备文件资源管理器

完整代码

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,
              ),
            ],
          ),
        ),
      ),
    );
  }
}