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

ぐ巨炮叔叔 提交于 2021-02-10 18:29:24

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/59053056/how-to-open-a-csv-file-like-url-launcher-in-flutter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!