CSV x Flutter, a true love?

What does this even mean? I don’t know.

Wow, wait a minute. CSV loves Flutter? Flutter loves CSV? Or I love you? (Ignore this please, I’m cringing with embarrassment myself). I don’t know, I’m using the first concept that comes into my mind while writing this. Just think about this as a clickbait, that I successfully baited you into clicking this article.

So, usually when you are working on a mobile app project using Flutter, your client may give you some CSV to visualize or work on your app. You need to understand how to read CSV in Flutter. I am going to give you some example in my project. Here’s a snapshot of the CSV I’m working on.

(Disclaimer: This is NOT the only way to read CSV in Flutter. I’m just telling you one of the ways)

First, you need to read your file and assign it to a variable.

Now you have the object in Flutter of your CSV file. You may think that we should have a list of list of strings, as it should be. That’s what we are going to do! Okay, to create list of row (list of strings), you can use this code:

Well, as you can see, now it’s a list of dynamic object. Usually, I convert this object into string, so I can use several string methods like split, etc. You can use the map method and then convert every column into string using the toString() method.

Voila! Now you have the lists containing your data from your CSV. Hope it’s useful for you, have a nice day!



A Computer Science Student at Universitas Indonesia

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store