フラッタインポートCSVファイルとリストに変換


Flutter CSV File ListView内のデータをインポートおよび表示します.
我々がカバーするこのポスト
  • CSVファイルをインポート
  • CSVファイルからデータを読み取り、リストに変換
  • ビューにCSVデータを表示する

  • dependencies:
      flutter:
        sdk: flutter
      csv: ^5.0.0
      path_provider: ^2.0.2
      permission_handler: ^7.1.0
      file_picker: ^3.0.4
    
    CSVファイルをインポート
    ファイルをインポートするには、FileCounterプラグインを使用します.このファイルピッカーには、speccificなファイルタイプを選ぶようなプロパティがあります.ここではcsvファイルをインポートしていますので、ファイルタイプとして拡張子を追加する必要があります.カスタム
    void _openFileExplorer() async {
    
      try {
    
        _paths = (await FilePicker.platform.pickFiles(
          type: _pickingType,
          allowMultiple: false,
          allowedExtensions: (_extension?.isNotEmpty ?? false)
              ? _extension?.replaceAll(' ', '').split(',')
              : null,
        ))
            ?.files;
      } on PlatformException catch (e) {
        print("Unsupported operation" + e.toString());
      } catch (ex) {
        print(ex);
      }
      if (!mounted) return;
      setState(() {
        openFile(_paths![0].path);
        print(_paths);
        print("File path ${_paths![0]}");
        print(_paths!.first.extension);
    
      });
    }
    
    CSVファイルからデータを読み込む
    openFile(filepath) async
    {
      File f = new File(filepath);
      print("CSV to List");
      final input = f.openRead();
      final fields = await input.transform(utf8.decoder).transform(new CsvToListConverter()).toList();
      print(fields);
      setState(() {
        employeeData=fields;
      });
    }
    
    ダウンロード完了コードFlutter CSV File 輸入