Skip to content

Commit 839c91e

Browse files
committed
💬 Add path entity update readme.
1 parent 2ca5ead commit 839c91e

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

README-ZH.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Language: [English](README.md) | 中文简体
3434
* [常见问题](#常见问题-)
3535
* [`xxx` 版本获取冲突 (例如 `dartx`)](#xxx-版本获取冲突-例如-dartx)
3636
* [如何获取资源的路径以进行上传或编辑等操作的整合?](#如何获取资源的路径以进行上传或编辑等操作的整合)
37+
* [如何更改“Recent”或其他路径的名称或属性?](#如何更改recent或其他路径的名称或属性)
3738
* [`File``Uint8List`创建`AssetEntity`的方法](#从file或uint8list创建assetentity的方法)
3839
* [控制台提示 'Failed to find GeneratedAppGlideModule'](#控制台提示-failed-to-find-generatedappglidemodule)
3940

@@ -294,6 +295,38 @@ dependency_overrides:
294295

295296
如果再此之后你仍然需要路径,那么可以通过已获得的 `File` 对象获取: `file.absolutePath`。
296297

298+
### 如何更改“Recent”或其他路径的名称或属性?
299+
300+
由 `photo_manager` 传递的 “Recent” 路径,包含了您设备上的所有的 `AssetEntity`。大部分的平台都会将这个路径命名为 “Recent”。尽管我们提供了自定义文字构建的能力,但是 `AssetPathEntity` 的名字或属性只能通过 `SortPathDelegate` 进行更改。这是你能访问到所有 `AssetPathEntity` 的唯一方法,或者说,是现阶段我们暴露出来的唯一方法。
301+
302+
若需要更改某一个路径的名字,继承 `SortPathDelegate` 并实现你自己的构建,接着像如下代码一样进行编写:
303+
304+
```dart
305+
/// 构建你自己的排序
306+
class CustomSortPathDelegate extends SortPathDelegate {
307+
const CustomSortPathDelegate();
308+
309+
@override
310+
void sort(List<AssetPathEntity> list) {
311+
///...///
312+
313+
// 在这里你可以对每个你认为需要的路径进行判断。
314+
// 我们唯一推荐更改的属性是 [name],
315+
// 并且我们不对更改其他属性造成的问题负责。
316+
for (final AssetPathEntity entity in list) {
317+
// 如果这个路径的 `isAll` 为真,则该路径就是你需要的。
318+
if (entity.isAll) {
319+
entity.name = '最近';
320+
}
321+
}
322+
323+
///...///
324+
}
325+
}
326+
```
327+
328+
将你的构建传递至静态调用方法里,而后你就会看到你自定义了名称的路径。
329+
297330
### `File``Uint8List`创建`AssetEntity`的方法
298331

299332
如果需要使用此库结合一些拍照需求,可通过以下方法将`File``Uint8List`转为`AssetEntity`

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ This project follows the [all-contributors](https://github.com/all-contributors/
5555
* [Frequent asked question](#frequent-asked-question-)
5656
* [Version resolve conflict with `xxx` (e.g. `dartx`)](#version-resolve-conflict-with-xxx-eg-dartx)
5757
* [How can I get path from the `AssetEntity` to integrate with `File` object, upload or edit?](#how-can-i-get-path-from-the-assetentity-to-integrate-with-file-object-upload-or-edit)
58+
* [How can I change the name of "Recent" or other entities name/properties?](#how-can-i-change-the-name-of-recent-or-other-entities-nameproperties)
5859
* [Create `AssetEntity` from `File` or `Uint8List` (rawData)](#create-assetentity-from-file-or-uint8list-rawdata)
5960
* [Console warning 'Failed to find GeneratedAppGlideModule'](#glide-warning-failed-to-find-generatedappglidemodule)
6061

@@ -315,6 +316,39 @@ You can always request the `File` object with `entity.originFile`, if `Uint8List
315316

316317
If you still needs path after requested the `File`, get it through `file.absolutePath`.
317318

319+
### How can I change the name of "Recent" or other entities name/properties?
320+
321+
The path entity called "Recent", brought by `photo_manager` in the path entities list, includes all `AssetEntity` on your device. "Recent" is a system named entity in most of platforms. While we provided ability to customize the text delegate, the name/properties can only be updated with `SortPathDelegate` . This is the only way that you have access to all path entities, or the only way that we exposed currently.
322+
323+
To change the name of the path entity, extend the `SortPathDelegate` with your own delegate, then write something like the code below:
324+
325+
```dart
326+
/// Create your own sort path delegate.
327+
class CustomSortPathDelegate extends SortPathDelegate {
328+
const CustomSortPathDelegate();
329+
330+
@override
331+
void sort(List<AssetPathEntity> list) {
332+
///...///
333+
334+
// In here you can check every path entities if you want.
335+
// The only property we recommend to change is [name],
336+
// And we have no responsibility for issues caused by
337+
// other properties update.
338+
for (final AssetPathEntity entity in list) {
339+
// If the entity `isAll`, that's the "Recent" entity you want.
340+
if (entity.isAll) {
341+
entity.name = 'Whatever you want';
342+
}
343+
}
344+
345+
///...///
346+
}
347+
}
348+
```
349+
350+
Pass the delegate through the static call method, then you will get a self-named path entity.
351+
318352
### Create `AssetEntity` from `File` or `Uint8List` (rawData)
319353

320354
In order to combine this package with camera shooting or something related, there's a solution about how to create an `AssetEntity` with `File` or `Uint8List` object.

0 commit comments

Comments
 (0)