Коммит 0cc706e0 создал по автору 4-alok's avatar 4-alok
Просмотр файлов

addded setCurrentStorage to controller

владелец c32945d3
......@@ -15,6 +15,7 @@ class _MyAppState extends State<MyApp> {
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(brightness: Brightness.dark),
home: HomePage(),
);
}
......@@ -31,10 +32,8 @@ class HomePage extends StatelessWidget {
appBar: AppBar(
actions: [
IconButton(
onPressed: () {
// contoller.sortByName();
},
icon: Icon(Icons.sort),
onPressed: () => controller.setCurrentStorage(strageIndex: 1),
icon: Icon(Icons.sd_storage_rounded),
)
],
leading: IconButton(
......@@ -50,7 +49,6 @@ class HomePage extends StatelessWidget {
child: FileManager(
controller: controller,
tileBuilder: (context, entity) {
// print(entity);
return Card(
child: ListTile(
leading: isFile(entity)
......
import 'dart:io';
import 'package:file_manager/file_manager.dart';
import 'package:flutter/material.dart';
......@@ -21,10 +20,9 @@ class FileManagerController extends ChangeNotifier {
Future<bool> goToParentDirectory() async {
List<Directory> storageList = (await getStorageList())!;
final bool willNotGoToParent = (storageList.where((element) {
print("${element.path} == ${Directory(_path).path}");
return element.path == Directory(_path).path;
}).isNotEmpty);
final bool willNotGoToParent = (storageList
.where((element) => element.path == Directory(_path).path)
.isNotEmpty);
if (!willNotGoToParent) openDirectory(Directory(_path).parent);
return willNotGoToParent;
}
......@@ -56,8 +54,9 @@ class FileManagerController extends ChangeNotifier {
int get getCurrentStorage => _currentStorage;
/// Set current storege. ie: 0 is for internal storage. 1, 2 and so on, if any external storage is available.
set setCurrentStorage(int index) {
_currentStorage = index;
Future<void> setCurrentStorage({required int strageIndex}) async {
_currentStorage = strageIndex;
_path = (await getStorageList())![strageIndex].path;
notifyListeners();
}
......
......@@ -17,26 +17,36 @@ bool isFile(FileSystemEntity entity) {
return (entity is File);
}
dirRename(FileSystemEntity dir, String name) {}
bool isDirectory(FileSystemEntity entity) {
return (entity is Directory);
}
/// Get the basename of Directory or File by providing FileSystemEntity entity.
/// Get the basename of Directory or File.
/// ie: controller.dirName(dir);
String basename(FileSystemEntity entity, [bool showFileExtension = true]) {
return (showFileExtension && (entity is File))
? entity.path.split('/').last.split('.').first
: entity.path.split('/').last;
String basename(dynamic entity, [bool showFileExtension = true]) {
if (entity is Directory) {
return entity.path.split('/').last;
} else if (entity is File) {
return (showFileExtension)
? entity.path.split('/').last.split('.').first
: entity.path.split('/').last;
} else {
print(
"Please provide a Object of type File, Directory or FileSystemEntity");
return "";
}
}
/// Get the basename of Directory by providing Directory.
String basenameDir(Directory dir) => dir.path.split('/').last;
// /// Get the basename of Directory by providing Directory.
// String basenameDir(Directory dir) => dir.path.split('/').last;
/// Get the basename of Fileby providing File.
String basenameFle(File file, {bool showFileExtension = false}) =>
showFileExtension
? file.path.split('/').last
: file.path.split('/').last.split('.').first;
// /// Get the basename of Fileby providing File.
// String basenameFle(File file, {bool showFileExtension = false}) =>
// showFileExtension
// ? file.path.split('/').last
// : file.path.split('/').last.split('.').first;
Future<List<Directory>?> getStorageList() async {
List<Directory>? storages = await getExternalStorageDirectories();
......@@ -78,16 +88,12 @@ class FileManager extends StatefulWidget {
class _FileManagerState extends State<FileManager> {
final ValueNotifier<String> path = ValueNotifier<String>("");
final ValueNotifier<int> currentStorage = ValueNotifier<int>(0);
@override
void initState() {
super.initState();
widget.controller.addListener(() {
path.value = widget.controller.getCurrentPath;
currentStorage.value = widget.controller.getCurrentStorage;
});
widget.controller
.addListener(() => path.value = widget.controller.getCurrentPath);
}
@override
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать