The list _data contain data from the csv file.
List<List<dynamic>> _data = [];
String key = "39";
List<List<dynamic>> _tempdata = [];
void _loadCSV() async {
final _rawData = await rootBundle.loadString("assets/mycsv.csv");
List<List<dynamic>> _listData =
const CsvToListConverter().convert(_rawData);
setState(() {
_data = _listData;
});
}
mycsv.csv data
id,Name,Num,Batch
15,JERRY,PH123,G9
27,Tom,PH129,G8
39,Oggy,PH124,G9
45,Jack,PH125,G10
I need to
Get the data where id == key(search element) from the list "_data" and store it in new list named "_tempdata"
>Solution :
You can use the where method of the List class to filter the elements of the _data list that match the condition you specified and store the result in a new list _tempdata. Here’s an example of how you can implement this in your code:
_tempdata = _data.where((element) => element[0] == key).toList();