Flutter: How to read data from simple spreadsheet?

岁酱吖の 提交于 2019-12-01 05:21:31

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

Hope this helps anyone having the same problem.

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