Home > database >  How to specify a path of file inside flutter project(How to retrieve CSV string inside flutter proje
How to specify a path of file inside flutter project(How to retrieve CSV string inside flutter proje

Time:03-30

For example, place the test.csv file directly under the lib directory of the flutter project.

If I want to get the CSV(string) in that file and do something with it when running the app, how do I get(retrieve) the CSV file?

CodePudding user response:

Generally external files are placed in an assets folder. Assuming you put it in the root of the assets folder. You need to do two manipulations.

  1. List this file as an asset in the pubspec.

    assets:

    • assets/my_csv_file.csv

2.Read it in your app.

import "package:flutter/services.dart" as s;

var csvData = await s.rootBundle.loadString("assets/my_csv_file.csv");

Edit : the assets folder is in the root of the project.

CodePudding user response:

By convention, you place any assets in a freshly created asset folder at the root of your project.

For getting those assets, you can use a dependency called path_provider that will allow you to get paths (temporary paths, project root folder etc..).

You will be interested in the project root folder and then navigate to the /asset folder or the /lib folder in the specific case of this question.

  • Related