I am new to Flutter. I am facing some issues while updating a list.
Currently, I have a list with some keys and values as follows:
[
{filename: aa},
{filename: bb.txt},
{filename: cc.txt}
]
And I want to update the above list by adding one more parameter called isPresent and update it as follows by doing some process on current data:
[
{filename: aa,
isPresent: false},
{filename: bb.txt,
isPresent: true},
{filename: cc.txt,
isPresent: false}
]
How to do that any idea?
To achieve the above updated list I am using the following code
final List<Map<String, dynamic>> list = [...fetchJsonData['data']];
list.asMap().forEach((key, value) async {
Directory? directory;
directory = await getExternalStorageDirectory();
File file = File("${directory!.path}/${list[key]['filename']}");
await io.File(file.path).exists();
bool isExists = io.File(file.path).existsSync();
print(isExists);
list[key]['isPresent'] = isExists;
});
fileList = list;
print(fileList);
but does not work with Await I think. Let me know if I am missing something.
3
Answers
You can do this for example
can you try below code and check :
Sure,