1+ import 'dart:io' ;
2+
13import 'package:file_manager/file_manager.dart' ;
24import 'package:flutter/material.dart' ;
35
@@ -26,14 +28,19 @@ class HomePage extends StatelessWidget {
2628
2729 @override
2830 Widget build (BuildContext context) {
31+ // Creates a widget that registers a callback to veto attempts by the user to dismiss the enclosing
32+ // or controllers the system's back button
2933 return WillPopScope (
3034 onWillPop: () async => (await controller.goToParentDirectory ()),
3135 child: Scaffold (
3236 appBar: AppBar (
3337 actions: [
3438 IconButton (
35- onPressed: () async =>
36- controller.openDirectory ((await getStorageList ())! .first),
39+ onPressed: () => sort (context),
40+ icon: Icon (Icons .sort_rounded),
41+ ),
42+ IconButton (
43+ onPressed: () => selectStorage (context),
3744 icon: Icon (Icons .sd_storage_rounded),
3845 )
3946 ],
@@ -49,18 +56,50 @@ class HomePage extends StatelessWidget {
4956 child: FileManager (
5057 controller: controller,
5158 builder: (context, snapshot) {
59+ final List <FileSystemEntity > entities = snapshot;
5260 return ListView .builder (
53- itemCount: snapshot .length,
61+ itemCount: entities .length,
5462 itemBuilder: (context, index) {
63+ FileSystemEntity entity = entities[index];
5564 return Card (
5665 child: ListTile (
57- leading: isFile (snapshot[index] )
66+ leading: isFile (entity )
5867 ? Icon (Icons .feed_outlined)
5968 : Icon (Icons .folder),
60- title: Text (basename (snapshot[index])),
61- onTap: () {
62- if (isDirectory (snapshot[index]))
63- controller.openDirectory (snapshot[index]);
69+ title: Text (basename (entity)),
70+ subtitle: subtitle (entity),
71+ onTap: () async {
72+ if (isDirectory (entity)) {
73+ // open the folder
74+ controller.openDirectory (entity);
75+
76+ // delete a folder
77+ // await entity.delete(recursive: true);
78+
79+ // rename a folder
80+ // await entity.rename("newPath");
81+
82+ // Check weather folder exists
83+ // entity.exists();
84+
85+ // get date of file
86+ // DateTime date = (await entity.stat()).modified;
87+ } else {
88+ // delete a file
89+ // await entity.delete();
90+
91+ // rename a file
92+ // await entity.rename("newPath");
93+
94+ // Check weather file exists
95+ // entity.exists();
96+
97+ // get date of file
98+ // DateTime date = (await entity.stat()).modified;
99+
100+ // get the size of the file
101+ // int size = (await entity.stat()).size;
102+ }
64103 },
65104 ),
66105 );
@@ -71,4 +110,99 @@ class HomePage extends StatelessWidget {
71110 )),
72111 );
73112 }
113+
114+ Widget subtitle (FileSystemEntity entity) {
115+ return FutureBuilder <FileStat >(
116+ future: entity.stat (),
117+ builder: (context, snapshot) {
118+ if (snapshot.hasData) {
119+ if (entity is File ) {
120+ int size = snapshot.data! .size;
121+ return Text (
122+ "$size " ,
123+ );
124+ }
125+ return Text (
126+ "${snapshot .data !.modified }" ,
127+ );
128+ } else {
129+ return Text ("" );
130+ }
131+ },
132+ );
133+ }
134+
135+ selectStorage (BuildContext context) {
136+ showDialog (
137+ context: context,
138+ builder: (context) => Dialog (
139+ child: FutureBuilder <List <Directory >>(
140+ future: getStorageList (),
141+ builder: (context, snapshot) {
142+ if (snapshot.hasData) {
143+ final List <FileSystemEntity > storageList = snapshot.data! ;
144+ return Padding (
145+ padding: const EdgeInsets .all (10.0 ),
146+ child: Column (
147+ mainAxisSize: MainAxisSize .min,
148+ children: storageList
149+ .map ((e) => ListTile (
150+ title: Text (
151+ "${basename (e )}" ,
152+ ),
153+ onTap: () {
154+ controller.openDirectory (e);
155+ Navigator .pop (context);
156+ },
157+ ))
158+ .toList ()),
159+ );
160+ }
161+ return Dialog (
162+ child: CircularProgressIndicator (),
163+ );
164+ },
165+ ),
166+ ),
167+ );
168+ }
169+
170+ sort (BuildContext context) async {
171+ showDialog (
172+ context: context,
173+ builder: (context) => Dialog (
174+ child: Container (
175+ padding: EdgeInsets .all (10 ),
176+ child: Column (
177+ mainAxisSize: MainAxisSize .min,
178+ children: [
179+ ListTile (
180+ title: Text ("Name" ),
181+ onTap: () {
182+ controller.sortedBy = SortBy .name;
183+ Navigator .pop (context);
184+ }),
185+ ListTile (
186+ title: Text ("Size" ),
187+ onTap: () {
188+ controller.sortedBy = SortBy .size;
189+ Navigator .pop (context);
190+ }),
191+ ListTile (
192+ title: Text ("Date" ),
193+ onTap: () {
194+ controller.sortedBy = SortBy .date;
195+ Navigator .pop (context);
196+ }),
197+ ListTile (
198+ title: Text ("type" ),
199+ onTap: () {
200+ controller.sortedBy = SortBy .type;
201+ Navigator .pop (context);
202+ }),
203+ ],
204+ ),
205+ ),
206+ ));
207+ }
74208}
0 commit comments