Коммит 47a364c8 создал по автору d.girenko's avatar d.girenko
Просмотр файлов

Move file_manager to lib/src directory

владелец ad71d61d
BSD 3-Clause License
(c) Copyright 2024 DevsOnFlutter Open Mobile Platform LLC <community@omp.ru>
(c) Copyright 2023 Alexander Syrykh
(c) Copyright 2021 DevsOnFlutter (Devs On Flutter)
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
......
# Change log
## 1.0.2
- Little optimization
- added FilesAccessPermission
## 1.0.1
- Reads dir from controller to let developer specify initial path before displaying
## 1.0.0
- Initial release.
BSD 3-Clause License
(c) Copyright 2021 DevsOnFlutter (Devs On Flutter)
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# File Manager
![FileManager-Banner](https://i.imgur.com/NNaUK60.png)
![GitHub](https://img.shields.io/github/license/DevsOnFlutter/file_manager?style=plastic) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/DevsOnFlutter/file_manager?style=plastic) ![GitHub top language](https://img.shields.io/github/languages/top/DevsOnFlutter/file_manager?style=plastic) ![GitHub language count](https://img.shields.io/github/languages/count/DevsOnFlutter/file_manager?style=plastic) ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/DevsOnFlutter/file_manager?style=plastic) ![GitHub issues](https://img.shields.io/github/issues/DevsOnFlutter/file_manager?style=plastic)
FileManager is a wonderful widget that allows you to manage files and folders, pick files and folders, and do a lot more.
Designed to feel like part of the Flutter framework.
## Compatibility
&nbsp; Android </br>
&nbsp; Linux </br>
&nbsp; Aurora </br>
&nbsp; Windows ([in progress](https://github.com/4-alok/file_manager/tree/windows-support))</br>
&nbsp; MacOS (active issue: [MacOS support](https://github.com/DevsOnFlutter/file_manager/issues/8)) </br>
## Usage
Make sure to check out [examples](https://github.com/DevsOnFlutter/file_manager/blob/main/example/lib/main.dart) for more details.
### Installation
**Dependencies** Add the following line to `pubspec.yaml`:
```yaml
dependencies:
file_manager: ^1.0.0
```
### Give storage permission to application
## Android
Beside needing to add **WRITE_EXTERNAL_STORAGE** , **READ_EXTERNAL_STORAGE** and **MANAGE_EXTERNAL_STORAGE** to your android/app/src/main/AndroidManifest.xml.
```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.yyy">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
...
</manifest>
```
also add for Android 10
```xml
<application
android:requestLegacyExternalStorage="true"
.../>
```
**You also need Runtime Request Permission**
allow storage permission from app setting manually or you may use any package such as [`permission_handler`](https://pub.dev/packages/permission_handler).
or use `FileManager` to request permission at runtime.
```dart
// request permission
await controller.requestFilesAccessPermission();
or
await FileManager.requestFilesAccessPermission();
```
</hr>
### Basic setup
*The complete example is available [here](https://github.com/DevsOnFlutter/file_manager/blob/main/example/lib/main.dart).*
Required parameter for **FileManager** are `controller` and `builder`
* `controller` The controller updates value and notifies its listeners, and FileManager updates itself appropriately whenever the user modifies the path or changes the sort-type with an associated FileManagerController.
```dart
final FileManagerController controller = FileManagerController();
```
* `builder` This function allows you to create custom widgets and retrieve a list of entities `List<FileSystemEntity>.`
## Sample code
```dart
FileManager(
controller: controller,
builder: (context, snapshot) {
final List<FileSystemEntity> entities = snapshot;
return ListView.builder(
itemCount: entities.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
leading: FileManager.isFile(entities[index])
? Icon(Icons.feed_outlined)
: Icon(Icons.folder),
title: Text(FileManager.basename(entities[index])),
onTap: () {
if (FileManager.isDirectory(entities[index])) {
controller.openDirectory(entities[index]); // open directory
} else {
// Perform file-related tasks.
}
},
),
);
},
);
},
),
```
</hr>
## FileManager
| Properties | Description |
|--------------|-----------------|
| `loadingScreen` | For the loading screen, create a custom widget. A simple Centered CircularProgressIndicator is provided by default. |
| `emptyFolder` | For an empty screen, create a custom widget. |
| `controller` | For an empty screen, create a custom widget. |
| `hideHiddenEntity` | Hide the files and folders that are hidden. |
| `builder` | This function allows you to create custom widgets and retrieve a list of entities `List<FileSystemEntity>.` |
## FileManagerController
| Properties | Description |
|--------------|-----------------|
| `getSortedBy` | The sorting type that is currently in use is returned. |
| `setSortBy` | is used to set the sorting type. `SortBy{ name, type, date, size }`. ie: `controller.sortBy(SortBy.date)` |
| `getCurrentDirectory` | Get current Directory |
| `getCurrentPath` | Get current path, similar to [getCurrentDirectory]. |
| `setCurrentPath` | Set current directory path by providing `String` of path, similar to [openDirectory]. `List<FileSystemEntity>.` |
| `isRootDirectory` | return true if current directory is the root. false, if the current directory not on root of the storage. |
| `goToParentDirectory` | Jumps to the parent directory of currently opened directory if the parent is accessible. |
| `openDirectory` | Open directory by providing `Directory`. |
| `titleNotifier` | ValueNotifier of the current directory's basename |
## ControlBackButton
When the current directory is not root, this widget registers a callback to prevent the user from dismissing the window, or controllers the system's back button
ie:-
```dart
// Wrap Scaffold containing FileManage with ControlBackButton
ControlBackButton(
controller: controller
child: Scaffold(
appBar: AppBar(...)
body: FileManager(
...
)
)
)
```
## Others
| Properties | Description |
|--------------|-----------------|
| `isFile` | check weather FileSystemEntity is File. |
| `isDirectory` | check weather FileSystemEntity is Directory. |
| `basename` | Get the basename of Directory or File. Provide `File`, `Directory` or `FileSystemEntity` and returns the name as a `String`. If you want to hide the extension of a file, you may use optional parameter `showFileExtension`. ie ```controller.dirName(dir, true)```|
| `formatBytes` | Convert bytes to human readable size.[getCurrentDirectory]. |
| `setCurrentPath` | Set current directory path by providing `String` of path, similar to [openDirectory]. `List<FileSystemEntity>.` |
| `getFileExtension` | Return file extension as String. ie:- `File("/../image.png")` to `"png"`. |
| `getStorageList` | Get list of available storage in the device, returns an empty list if there is no storage `List<Directory>`|
| `createFolder` | Creates the directory if it doesn't exist. Requires currentPath and Name of the Directory. |
</hr>
<p>
<img width="205px" height ="444px" alt="Example" src="https://imgur.com/RXwvwB9.gif"/>
<img width="205px" height ="444px" alt="Example" src="https://imgur.com/a56XQv7.png"/>
<img width="205px" height ="444px" alt="Example" src="https://imgur.com/q4Ouf3M.png"/>
<img width="205px" height ="444px" alt="Example" src="https://imgur.com/CwB5wb0.png"/>
</p>
</hr>
## Show some :heart: and :star: the repo
![GitHub Repo stars](https://img.shields.io/github/stars/DevsOnFlutter/file_manager?style=social)
![GitHub forks](https://img.shields.io/github/forks/DevsOnFlutter/file_manager?style=social)
[![GitHub followers](https://img.shields.io/github/followers/4-alok?style=social)](https://github.com/4-alok/)
## Project Created & Maintained By
* ### [DevsOnFlutter](https://github.com/DevsOnFlutter)
</hr>
## Contributions
Contributions are welcomed!
If you feel that a hook is missing, feel free to open a pull-request.
For a custom-hook to be merged, you will need to do the following:
* Describe the use-case.
* Open an issue explaining why we need this hook, how to use it, ...
This is important as a hook will not get merged if the hook doesn't appeal to
a large number of people.
* If your hook is rejected, don't worry! A rejection doesn't mean that it won't
be merged later in the future if more people shows an interest in it.
In the mean-time, feel free to publish your hook as a package on <https://pub.dev>.
* A hook will not be merged unless fully tested, to avoid breaking it inadvertently
in the future.
export 'package:file_manager/controller/file_manager_controller.dart';
export 'package:file_manager/enums/sort_by.dart';
name: file_manager
description: FileManager is a wonderful widget that allows you to manage files
and folders, pick files and folders, and do a lot more. Designed to feel like
part of the Flutter framework.
version: 1.0.2
homepage: https://github.com/DevsOnFlutter
repository: https://github.com/DevsOnFlutter/file_manager
documentation: https://github.com/DevsOnFlutter/file_manager/blob/main/README.md
environment:
sdk: ">=2.12.0 <4.0.0"
dependencies:
flutter:
sdk: flutter
path_provider: ^2.0.11
dev_dependencies:
flutter_test:
sdk: flutter
// SPDX-FileCopyrightText: Copyright 2021 DevsOnFlutter (Devs On Flutter)
// SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
import 'dart:io';
import 'package:file_manager/file_manager.dart';
import 'package:flutter/widgets.dart';
import '../file_manager.dart';
import '../helper/helper.dart';
class FileManagerController {
final ValueNotifier<String> _path = ValueNotifier<String>('');
final ValueNotifier<SortBy> _short = ValueNotifier<SortBy>(SortBy.name);
......
......@@ -6,13 +6,13 @@ library file_manager;
import 'dart:io';
import 'dart:math' as math;
import 'package:file_manager/utils/extensions.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:file_manager/helper/helper.dart';
export 'package:file_manager/helper/helper.dart';
import 'controller/file_manager_controller.dart';
import 'enums/sort_by.dart';
import 'utils/extensions.dart';
const _methodChannel = MethodChannel('myapp/channel');
......
// SPDX-FileCopyrightText: Copyright 2021 DevsOnFlutter (Devs On Flutter)
// SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
export '../controller/file_manager_controller.dart';
export '../enums/sort_by.dart';
......@@ -18,8 +18,6 @@ dependencies:
sdk: flutter
plugin_platform_interface: ^2.0.2
file_selector_platform_interface: ^2.6.0
file_manager:
path: file_manager
mime: ^1.0.5
flutter_svg: ^2.0.10+1
path_provider: ^2.0.15
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать