Skip to content

Commit f3f4676

Browse files
committed
added createFolder
1 parent 9ab769e commit f3f4676

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ FileManager(
137137
| `formatBytes` | Convert bytes to human readable size.[getCurrentDirectory]. |
138138
| `setCurrentPath` | Set current directory path by providing `String` of path, similar to [openDirectory]. `List<FileSystemEntity>.` |
139139
| `getStorageList` | Get list of available storage in the device, returns an empty list if there is no storage `List<Directory>`|
140+
| `createFolder` | Creates the directory if it doesn't exist. Requires currentPath and Name of the Directory. |
140141

141142
## Show some :heart: and :star: the repo
142143

@@ -148,7 +149,6 @@ FileManager(
148149

149150
* ### [DevsOnFlutter](https://github.com/DevsOnFlutter)
150151

151-
152152
</hr>
153153

154154
## Contributions

example/lib/main.dart

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -226,22 +226,39 @@ class HomePage extends StatelessWidget {
226226
createFolder(BuildContext context) async {
227227
showDialog(
228228
context: context,
229-
builder: (context) => Dialog(
230-
child: Container(
231-
padding: EdgeInsets.all(10),
232-
child: Column(
233-
mainAxisSize: MainAxisSize.min,
234-
children: [
235-
ListTile(
236-
title: Text("Name"),
237-
onTap: () {
238-
controller.sortedBy = SortBy.name;
229+
builder: (context) {
230+
TextEditingController folderName = TextEditingController();
231+
return Dialog(
232+
child: Container(
233+
padding: EdgeInsets.all(10),
234+
child: Column(
235+
mainAxisSize: MainAxisSize.min,
236+
children: [
237+
ListTile(
238+
title: TextField(
239+
controller: folderName,
240+
),
241+
),
242+
ElevatedButton(
243+
onPressed: () async {
244+
try {
245+
// Create Folder
246+
await FileManager.createFolder(
247+
controller.getCurrentPath, folderName.text);
248+
// Open Created Folder
249+
controller.setCurrentPath =
250+
controller.getCurrentPath + "/" + folderName.text;
251+
} catch (e) {}
252+
239253
Navigator.pop(context);
240-
}),
241-
],
254+
},
255+
child: Text('Create Folder'),
256+
)
257+
],
258+
),
242259
),
243-
),
244-
),
260+
);
261+
},
245262
);
246263
}
247264
}

lib/file_manager.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ class FileManager extends StatefulWidget {
227227
}
228228
}
229229

230+
/// Creates the directory if it doesn't exist.
231+
static Future<void> createFolder(String currentPath, String name) async {
232+
await Directory(currentPath + "/" + name).create();
233+
}
234+
230235
/// Get list of available storage in the device
231236
/// returns an empty list if there is no storage
232237
static Future<List<Directory>> getStorageList() async {

0 commit comments

Comments
 (0)