I am trying to download some files in a flutter application. After the files are downloaded, I want to be able to show the downloads to the user with files and their information like date modified, size etc. Right now I am retrieving list of files like this:
import 'dart:io' as io;
import 'package:flutter/material.dart';
import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart';
class Downloads extends StatefulWidget {
@override
_DownloadsState createState() => _DownloadsState();
}
class _DownloadsState extends State<Downloads> {
String directory;
List file = new List();
@override
void initState() {
super.initState();
_listofFiles();
}
void _listofFiles() async {
directory = (await getExternalStorageDirectory()).path;
setState(() {
file = io.Directory("$directory/").listSync();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Downloads"),
),
body: GridView.builder(
padding: EdgeInsets.all(10),
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
childAspectRatio: 0.9),
itemCount: file.length,
itemBuilder: (context, i) {
print(file[i]);
return GestureDetector(
onTap: () {
OpenFile.open(file[i].toString());
},
child: Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey, blurRadius: 2, spreadRadius: 2),
]),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(
Icons.insert_drive_file,
size: 50,
color: Colors.blue,
),
SizedBox(height: 10),
Text(file[i].toString())
],
),
),
);
}),
);
}
}
But I am only able to get the file path from the above code and not the fileName and file extension or file size. How do I retrieve those information?