Want to read data from simple spreadsheet in Flutter? 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:
1 2 3 | flutter: assets: - assets/res/Book1.csv |
Then declare both functions and just call loadCSV() when you want to load the data.
1 2 3 4 5 6 7 8 9 | Future<String> loadAsset(String path) async { return await rootBundle.loadString(path); } void loadCSV() { loadAsset('assets/res/Book1.csv').then((dynamic output) { csvRaw = output; }); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.