I have a .txt
file in my folder assets in the Flutter project and when the app is open on a device a SQFlite
database is created and should read from this file lines to insert them in the Database. I need to read each line of the .txt
file and add them to a List<String>
like this :
List<String> _list = await new File('$dir/assets/file.txt').readAsLines();
I have try to use rootBundle
but I can't convert the result as a File
and by trying to open the file directly like this :
String dir = (await getApplicationDocumentsDirectory()).path;
I always can't find the file and get an error.
var byte = await rootBundle.load('assets/bot.txt'); // Can't convert it to file
String dir = (await getApplicationDocumentsDirectory()).path;
List<String> _list = await new File('$dir/assets/file.txt').readAsLines(); // Error
error FileSystemException: Cannot open file, path = '/data/user/0/com.example.animationexp/app_flutter/assets/file.txt' (OS Error: No such file or directory, errno = 2) during open, closing...
Is there a solution for me to open and read this file ?