Skip to content

Commit b8d4395

Browse files
authored
Merge pull request #2 from Arpit-Sahu/main
controller added for sort and back button.
2 parents aedd091 + 0ae399d commit b8d4395

File tree

9 files changed

+92
-6
lines changed

9 files changed

+92
-6
lines changed

example/android/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>android</name>
4+
<comment>Project android created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
arguments=
2+
auto.sync=false
3+
build.scans.enabled=false
4+
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
5+
connection.project.dir=
6+
eclipse.preferences.version=1
7+
gradle.user.home=
8+
java.home=C\:/Program Files/Java/jdk-14.0.1
9+
jvm.arguments=
10+
offline.mode=false
11+
override.workspace.settings=true
12+
show.console.view=true
13+
show.executions.view=true

example/android/app/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14/"/>
4+
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
5+
<classpathentry kind="output" path="bin/default"/>
6+
</classpath>

example/android/app/.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>app</name>
4+
<comment>Project app created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
connection.project.dir=..
2+
eclipse.preferences.version=1

example/lib/main.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class HomePage extends StatelessWidget {
2727
Widget build(BuildContext context) {
2828
return WillPopScope(
2929
onWillPop: () async {
30-
return true;
30+
return await controller.goToParentDirectory();
3131
},
3232
child: Scaffold(
3333
appBar: AppBar(
@@ -41,7 +41,11 @@ class HomePage extends StatelessWidget {
4141
],
4242
leading: IconButton(
4343
icon: Icon(Icons.arrow_back),
44-
onPressed: () {},
44+
onPressed: () async {
45+
if (!(await controller.goToParentDirectory())) {
46+
Navigator.pop(context);
47+
}
48+
},
4549
),
4650
),
4751
body: Container(

lib/controller/file_manager_controller.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:io';
22

3+
import 'package:file_manager/file_manager.dart';
34
import 'package:flutter/material.dart';
45

56
class FileManagerController extends ChangeNotifier {
@@ -18,6 +19,26 @@ class FileManagerController extends ChangeNotifier {
1819
notifyListeners();
1920
}
2021

22+
Future<bool> goToParentDirectory() async {
23+
List<Directory> storageList = (await getStorageList())!;
24+
bool willNotGoToParent = storageList
25+
.where((element) => element.path == Directory(_path).path)
26+
.isEmpty;
27+
print(Directory(_path).parent);
28+
if (!willNotGoToParent) {
29+
openDirectory(Directory(_path).parent);
30+
}
31+
return willNotGoToParent;
32+
}
33+
34+
// List<FileSystemEntity> sort(SortBy sort, List<FileSystemEntity> entitys) {
35+
// if (sort == SortBy.name) {
36+
// entitys
37+
// .sort((a, b) => a.path.toLowerCase().compareTo(b.path.toLowerCase()));
38+
// return entitys;
39+
// } else if (sort == SortBy.date) {}
40+
// }
41+
2142
/// Open directory by providing Directory.
2243
void openDirectory(FileSystemEntity entity) {
2344
if (entity is Directory) {

lib/enums/sort_by.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
enum SortBy {
22
name,
33
date,
4-
}
4+
}

lib/file_manager.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ class _FileManagerState extends State<FileManager> {
9595
return FutureBuilder<List<Directory>?>(
9696
future: getStorageList(),
9797
builder: (context, snapshot) {
98-
print(snapshot.data);
9998
if (snapshot.hasData) {
10099
path.value = snapshot.data![0].path;
101100
return body(context);
102101
} else if (snapshot.hasError) {
103-
print(snapshot.error);
104-
return errorPage(snapshot.error.toString());
102+
// print(snapshot.error);
103+
throw Exception(snapshot.error.toString());
104+
// return errorPage(snapshot.error.toString());
105105
} else {
106106
return loadingScreenWidget();
107107
}

0 commit comments

Comments
 (0)