I'm receiving data from the csv file as
SERVICE_ID‡WEIGHT_ID‡DISTANCE_ID‡BASE_PRICE‡IDENTIFIER
PARCEL‡W0‡‡0.00‡N
PARCEL‡W1‡‡19.00‡N
Upon extracting this file with the help of CsvToListConverter()
I was able to print the data as
[SERVICE_ID, WEIGHT_ID, DISTANCE_ID, BASE_PRICE, IDENTIFIER
PARCEL, W0, , 0.00, N
PARCEL, W1, , 19.00, N]
So i just removed the first row by using the range property result.removeRange(0, 4);
and printed the result as
[PARCEL, W0, , 0.00, N
PARCEL, W1, , 19.00, N]
Actually the 4 index is being taken both N & Parcel together
If i print result[4], I'm getting as NParcel
where in it should be only N
This is the model representation
class mode {
final String type;
final String code;
final String isSent;
final String price;
final String delivered;
mode(this.type, this.code, this.isSent, this.price, this.delivered)
}
How to extract the data?
Note There is no Comma
symbol after N nor any new line \n
code
CodePudding user response:
CSV Data can extract like this,
class RowData
{
final String Column1;
final String Column2;
RowData(this.Column1, this.Column2)
}
List <RowData> tableData = [];
int colCount = 2;
List rawDataList = ["H1", "H2", "R1C1", "R1C2", "R2C1", "R2C2"];
for(int i = colCount - 1; i < rawDataList.length / colCount; i = colCount)
{
tableData.add(rawDataList[i], rawDataList[i 1]);
}
CodePudding user response:
you can create a list of mode
like this:
List list =
['PARCEL', 'W0','' , 0.00, 'N'
'PARCEL', 'W1', '', 19.00, 'N'];
List <mode> modeList = [];
for (int i=0;i<list.length/5;i ){
modeList.add(mode(list[i],list[i 1],list[i 2],list[i 3],list[i 4]));
}