I have csv file with 44k lines. Each line have 3 tab separated fields. Have to load data in Flutter app, but not sure about performance.
Data will be used to search inside. Not just showing it. Any suggestions?
CodePudding user response:
My suggestion would be for you to convert your csv file into json, that way you can map your data into objects more easily.
final String jsonString = await rootBundle.loadString('assets/your_file.json');
List<dynamic> objects = await json.decode(jsonString);
List<Model> modelList =
objects.map((e) => Model.fromJsonFile(e)).toList();
factory Model.fromJsonFile(Map<String, dynamic> data) {
return Model(
id: data['id'],
property1: data['property1'],
);
}
After that, work just with the list of objects, not with the file itself.
Use can also use compute or isolates to read the file and map it to objects, it will help with performance. Here's a good example on using compute to read data from servers. In your case, you'll use a local file instead of a response.