Replies: 7 comments 4 replies
-
或者可以这么说,Provider和Delegate本身实现逻辑上就是具有强关联的,因此我们更加不能去限制它们之间的组合关系:因为这完全应当是由继承实现类来决定的,抽象的Delegate基类不该持有Provider。当然这涉及到Flutter Provider库本身的局限(由于动态性,需要“飞线”,无法静态定位)。 |
Beta Was this translation helpful? Give feedback.
-
我个人基本认同你的观点,而且这部分因为没有严格的去做分层架构,所以只是提供了点到点的重载。如果可以的话,我也希望能整理一套完善、美观且灵活的架构。 有时间的话,希望你可以帮忙做一份架构模拟设计,我们深入讨论一下怎么把它变得好用(正在回家路上) Converting this as a discussion according to contents related with this issue. |
Beta Was this translation helpful? Give feedback.
-
今天在我的Fork里做了初步修改,糊出来一个初步实现。发现最关键的还是对AssetPickerProvider这个抽象基类进行关注点分离,里面存在例如isSwitchingPath这种和UI有关的逻辑。目前是靠一个ProviderAggregate类进行一个全局封装。 |
Beta Was this translation helpful? Give feedback.
-
我将在 #241 中进行调整,目前已经将 provider 从抽象 delegate 中拆分,并且优化了一些方法的耦合情况。可以订阅 PR 并且关注实现情况,及时沟通。 |
Beta Was this translation helpful? Give feedback.
-
已合并至 34f133f,并且在 example 中添加了一个示例。 |
Beta Was this translation helpful? Give feedback.
-
More on this topic: On the UI side, I find the delegate pattern of customizing UI getting bloated and rigid. We should start extracting codes, apply the rule of "Composition over Inheritance" , and we build the whole thing by compositing UI pieces into just a To make a TabView you will need Vsync, which was not provided (not mixed in) in the top-level State before, so you monkey-patched it. What if the next time someone need some other mixin on All an UI-developer need is the injected-provider and handy building blocks of the UI, functions like gridBuilder, itemBuilder, appBar, bottomAppBar and buttons. We should not be passing a delegate, instead devs should simply pass a Stateful/less Widget Page and we devs guarantee it works with our custom providers. I will spend some time on revamping it with my own ideas (this weekend), that's going to introduce a lot of big changes so I won't PR early on. Off-topic: That's why I really hate Java, turned to Flutter and never really learnt Android Native, and started learning Go recently. |
Beta Was this translation helpful? Give feedback.
-
Tried to implement a lazy loading mechanism today in the |
Beta Was this translation helpful? Give feedback.
-
首先感谢作者为我们提供如此强大的文件选择库(Flutter上其他的库都太不好用了吧!)。
First thank you all for building us such a powerful asset-picker library! All other libraries are literally toys compared to this one.
但是,在我尝试避免造轮子、在本插件的基础上写逻辑的时候遇到了困难:Delegate和Provider之间是耦合的(Delegate的构造函数接受且只接受一个Provider,而一个Provider只维护了一个_currentAssets,这限定死了一对一关系)。
However I encountered problems while trying to reuse the codebase and implement a custom file picker: the Delegate and Providers are tightly coupled. (the constructor of a AssetPickerBuilderDelegate takes one and only one provider, and a provider maintains only one _currentAssets, limiting it to a one-on-one relation).
我要造的轮子就是模仿小红书的文件选择页面:
I was trying to imitate the following UI (Switch asset type by Tabs).
这个根据Tab切换所选文件类型的功能,只是通过继承Delegate、Provider类是无法较好实现的:如果通过先全部加载,再在UI逻辑里条件筛选的方式,可能会有数据显示不全,而且影响加载更多的交互等逻辑。
This feature cannot be implemented by extending delegate and provider classes. If I try the hack way which is loading AssetType.common first then filter it in UI logics (I tried), it would cause incomplete file result, and mess up with the interactions/load more logics.
一个可能的实现是,一个Tab对应一个Provider,而Provider在实例化的时候配置不同的类型。但是现有的Delegate模型不允许我这么做。
A possible implementation being, one Tab corresponds to one Provider(or data source, since we logically can't have multiple Provider the Widget of same Type in the hierarchy), and config them with different RequestTypes on instantiating. But the current model of delegate won't allow me to do so.
实际上,父级抽象类 AssetPickerBuilderDelegate 对provider的依赖是完全可以消除的,仅有的两个逻辑,要么可以从AssetPicker那几个静态方法从上层注入Provider,要么可以交给子类实现。
IMO the dependency of a provider in the parent abstract class AssetPickerBuilderDelegate can be eliminated! the only existing 2 uses can be eliminated by injecting it from AssetPicker#pickAssetsWithDelegates or leave it to the child class to implement it.
我们可以先讨论一下这个问题可能的解决,如果有时间我近期会提个PR!(这可能引入Breaking changes,虽然如果不自定义可能不用更改)
We can discuss for a possible solution first, maybe I'll PR in a short time! (Might introduce breaking changes, although no modification is needed if you don't do customization)
Beta Was this translation helpful? Give feedback.
All reactions