Skip to content

Commit 6bb2d45

Browse files
author
Arpit-Sahu
committed
Api Documentation
1 parent 2c1b22a commit 6bb2d45

File tree

3 files changed

+62
-8
lines changed

3 files changed

+62
-8
lines changed

example/lib/main.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:io';
2-
31
import 'package:file_manager/file_manager.dart';
42
import 'package:flutter/material.dart';
53

@@ -34,7 +32,7 @@ class HomePage extends StatelessWidget {
3432
appBar: AppBar(
3533
actions: [
3634
IconButton(
37-
onPressed: () => controller.setCurrentStorage(strageIndex: 1),
35+
onPressed: () => controller.setCurrentStorage(storageIndex: 1),
3836
icon: Icon(Icons.sd_storage_rounded),
3937
)
4038
],

lib/controller/file_manager_controller.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ class FileManagerController extends ChangeNotifier {
88
SortBy _short = SortBy.size;
99

1010
// TODO: [Documentation]
11+
12+
/// getSorted by returns the current sorting type of the FileManager
1113
SortBy get getSortedBy => _short;
1214
// TODO: [Documentation]
15+
/// setSortedBy is used to set the sorting type.
1316
set setSortedBy(SortBy sortType) {
1417
_short = sortType;
1518
notifyListeners();
@@ -28,6 +31,8 @@ class FileManagerController extends ChangeNotifier {
2831
}
2932

3033
// TODO: [Documentation]
34+
/// goToParentDirectory returns false and goes to the parent directory of currently opened directory if the parent is accessible,
35+
/// it will return true and pops the screen if the parent of currently opened directory is not accessible.
3136
Future<bool> goToParentDirectory() async {
3237
List<Directory> storageList = (await getStorageList())!;
3338
final bool willNotGoToParent = (storageList
@@ -52,9 +57,9 @@ class FileManagerController extends ChangeNotifier {
5257
int get getCurrentStorage => _currentStorage;
5358

5459
/// Set current storege. ie: 0 is for internal storage. 1, 2 and so on, if any external storage is available.
55-
Future<void> setCurrentStorage({required int strageIndex}) async {
56-
_currentStorage = strageIndex;
57-
_path = (await getStorageList())![strageIndex].path;
60+
Future<void> setCurrentStorage({required int storageIndex}) async {
61+
_currentStorage = storageIndex;
62+
_path = (await getStorageList())![storageIndex].path;
5863
notifyListeners();
5964
}
6065
}

lib/file_manager.dart

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
2224
Future<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
100103
bool 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
105109
bool 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
111117
String 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
126133
Future<List<Directory>?> getStorageList() async {
127134
if (Platform.isAndroid) {
128135
List<Directory> storages = (await getExternalStorageDirectories())!;
@@ -148,10 +155,41 @@ Future<List<Directory>?> getStorageList() async {
148155

149156
class 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

Comments
 (0)