'Parsing csv data - Flutter

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



Solution 1:[1]

I do not know why it does not work for you, but this example works without problems.

import 'package:fast_csv/fast_csv_ex.dart' as fast_csv_ex;

void main(List<String> args) {
  final records = fast_csv_ex.parse(_data, separator: '‡');
  final r1 = records[1];
  final r2 = records[2];
  print(r1[4]);
  print(r2[0]);
  print(r2);
}

const _data = '''
SERVICE_ID‡WEIGHT_ID‡DISTANCE_ID‡BASE_PRICE‡IDENTIFIER
PARCEL‡W0‡‡0.00‡N
PARCEL‡W1‡‡19.00‡N''';

Output:

N
PARCEL
[PARCEL, W1, , 19.00, N]

Solution 2:[2]

Thanks everyone for your suggestions, finally solved it by using the string split method by tariffFields.toString().replaceAll("[", "").replaceAll("]", "").split("\n");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mezoni
Solution 2 Niroop Nife