简体   繁体   中英

Flutter: how to read a csv from assets

I was messing with the csv 4.1.0 package and csv_reader but I can't figure out how to read a csv:c Is there any easy way/recipe to implement a "reader" and get a kind of list of lists?

I've tried List<List<dynamic>> data = const CsvToListConverter().convert("assets/csv/name.csv"); then I do print(data) and I get flutter: [[assets/csv/name.csv]]

Note: I have added my csv as a dependency in the pubspec.yaml file in assets

I want to get this csv: https://gist.github.com/armgilles/194bcff35001e7eb53a2a8b441e8b2c6

Thank you

include this in your pubspec.yaml: csv: ^4.1.0 (The Current Version) You can use the package import 'package:csv/csv.dart'; Inside you have a method called CsvToListConverter(), using this you can convert your CSV data to a nice list.

import 'package:csv/csv.dart';
...
List<List<dynamic>> rowsAsListOfValues = const CsvToListConverter().convert(data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM