Flutter: How to read data from simple spreadsheet?

前端 未结 1 1026
陌清茗
陌清茗 2021-01-05 10:54

I am new to flutter and a have question that shouldn\'t be to hard to answer for a pro.

I have a simple spreadsheet with 5 columns and 10 rows. Now I have two variab

相关标签:
1条回答
  • 2021-01-05 11:53

    Thanks for your answers. I made it work using async and await as can be seen in the following. Important as well is to declare the asset file in your pubspec.yaml like

    flutter:
      assets:
        - assets/res/Book1.csv
    

    Then declare both functions and just call loadCSV() when you want to load the data.

    Future<String> loadAsset(String path) async {
       return await rootBundle.loadString(path);
    }
    
    void loadCSV() {
      loadAsset('assets/res/Book1.csv').then((dynamic output) {
        csvRaw = output;
      });
    }
    
    0 讨论(0)
提交回复
热议问题