@@ -19,6 +19,8 @@ class _PathStat {
1919 _PathStat (this .path, this .dateTime);
2020}
2121
22+ ///sort the files and folders according to the SortBy type
23+ ///It will return a list of fileSystemEntity after sorting
2224Future <List <FileSystemEntity >> _sortEntitysList (
2325 String path, SortBy sortType) async {
2426 final List <FileSystemEntity > list = await Directory (path).list ().toList ();
@@ -96,18 +98,22 @@ Future<List<FileSystemEntity>> _sortEntitysList(
9698 return [];
9799}
98100
99- // check weather FileSystemEntity is Fille
101+ /// check weather FileSystemEntity is File
102+ /// return true if FileSystemEntity is a File else returns false
100103bool isFile (FileSystemEntity entity) {
101104 return (entity is File );
102105}
103106
104107// check weather FileSystemEntity is Directory
108+ /// return true if FileSystemEntity is a Directory else returns Directory
105109bool isDirectory (FileSystemEntity entity) {
106110 return (entity is Directory );
107111}
108112
109113/// Get the basename of Directory or File.
114+ /// takes the directory and returns the name of file or folder
110115/// ie: controller.dirName(dir);
116+ /// to hide the extension of file, showFileExtension = flase
111117String basename (dynamic entity, [bool showFileExtension = true ]) {
112118 if (entity is Directory ) {
113119 return entity.path.split ('/' ).last;
@@ -122,7 +128,8 @@ String basename(dynamic entity, [bool showFileExtension = true]) {
122128 }
123129}
124130
125- // Get list of available storage directories
131+ /// Get list of available storage in the device
132+ /// returns an empty list if there is no storage
126133Future <List <Directory >?> getStorageList () async {
127134 if (Platform .isAndroid) {
128135 List <Directory > storages = (await getExternalStorageDirectories ())! ;
@@ -148,10 +155,41 @@ Future<List<Directory>?> getStorageList() async {
148155
149156class FileManager extends StatefulWidget {
150157 /// Provide a custom widget for loading screen.
158+ /// as default CircularProgressIndicator is provided.
151159 final Widget ? loadingScreen;
160+
161+ /// Provide a scroll Physics for scrolling behaviour.
152162 final ScrollPhysics ? physics;
163+
164+ ///shrinkwrap will only occupy the space it need
153165 final bool shrinkWrap;
166+
154167 final FileManagerController controller;
168+
169+ ///Builder is a custom builder which takes an entity and bulds a widget around it
170+ ///
171+ ///
172+ ///```
173+ /// builder: (context, snapshot) {
174+ /// return ListView.builder(
175+ /// itemCount: snapshot.length,
176+ /// itemBuilder: (context, index) {
177+ /// return Card(
178+ /// child: ListTile(
179+ /// leading: isFile(snapshot[index])
180+ /// ? Icon(Icons.feed_outlined)
181+ /// : Icon(Icons.folder),
182+ /// title: Text(basename(snapshot[index])),
183+ /// onTap: () {
184+ /// if (isDirectory(snapshot[index]))
185+ /// controller.openDirectory(snapshot[index]);
186+ /// },
187+ /// ),
188+ /// );
189+ /// },
190+ /// );
191+ /// },
192+ /// ```
155193 final _Builder builder;
156194
157195 /// Hide the hidden file and folder.
@@ -177,12 +215,21 @@ class _FileManagerState extends State<FileManager> {
177215 @override
178216 void initState () {
179217 super .initState ();
218+ /// add the listner to the contoller
180219 widget.controller.addListener (() {
181220 path.value = widget.controller.getCurrentPath;
182221 sort.value = widget.controller.getSortedBy;
183222 });
184223 }
185224
225+ /// dispose all the value notifiers
226+ @override
227+ void dispose () {
228+ path.dispose ();
229+ sort.dispose ();
230+ super .dispose ();
231+ }
232+
186233 @override
187234 Widget build (BuildContext context) {
188235 return FutureBuilder <List <Directory >?>(
@@ -201,6 +248,7 @@ class _FileManagerState extends State<FileManager> {
201248 );
202249 }
203250
251+ /// main body of File Manager can fetch data from the device
204252 Widget body (BuildContext context) {
205253 return ValueListenableBuilder <String >(
206254 valueListenable: path,
@@ -236,6 +284,7 @@ class _FileManagerState extends State<FileManager> {
236284 );
237285 }
238286
287+ /// error page that displays the error in the screen
239288 Container errorPage (String error) {
240289 return Container (
241290 color: Colors .red,
@@ -245,6 +294,8 @@ class _FileManagerState extends State<FileManager> {
245294 );
246295 }
247296
297+ /// loading screen if the backend is currently fecthing data from the device.
298+ /// It will display simple Circular Progress Indicator if no custom widget is passed.
248299 Widget loadingScreenWidget () {
249300 if ((widget.loadingScreen == null )) {
250301 return Container (
0 commit comments