I was trying to get all pdf files from device storage and it's done now I want to show the size of that file in listview. builder trailing.
path of my file
files[index].path
print of files[index].path is /storage/emulated/0/android/data/......../name.pdf
this is what im trying
title: Text(files[index].path.split('/').last),
trailing: Text(files[index].path.length()),
CodePudding user response:
If your list type is File
you can get that with length()
:
var size = await files[index].length();
print(size);
If not try this:
var size = await File(files[index].path).length();
print(size);
also you can't call it direct in Text
widget, first you need call it in FutureBuilder
, second you need to parse its value to string like this:
trailing: FutureBuilder<int>(
builder: (context, snapshot) {
return Text(snapshot.data.toString());
},
future: files[index].length(),
),
CodePudding user response:
Try this
int sizeInBytes = File(files[index].path).lengthSync();