Replies: 6 comments 9 replies
-
That's not reasonable. It isn't meant to be used You don't need the mixin PaginationMixin<T> {
State<AsyncValue<T>> get state;
set state(State<AsyncValue<T> value);
Ref<AsyncValue<T>> get ref;
} If you end up needing this often, you can make an interface abstract class AsyncNotifierInterface<T> {
State<AsyncValue<T>> get state;
set state(State<AsyncValue<T> value);
Ref<AsyncValue<T>> get ref;
}
mixin MyMixin<T> implements AsyncNotifierInterface<T> {
} |
Beta Was this translation helpful? Give feedback.
-
I'll maybe expose it in the future, but I'm a bit skeptical about it for now. It's not something that was designed to be exposed. I'd need to carefully review it before exposing it. |
Beta Was this translation helpful? Give feedback.
-
@rrousselGit Well, I've just thought that it could be possible to expose both Buildless and general Notifiers, if one had already been exposed, but I understand your skepsis about it. Anyway your workaround functions excellent, thank you! And I just want to specify two more things:
If I try to use it like that: mixin PaginationMixin<T> {
Ref<PaginationState<T>> get ref; There is and error, if I try to use the mixin: It is solved, if I create mixin this way: mixin PaginationMixin<T> {
AutoDisposeAsyncNotifierProviderRef<PaginationState<T>> get ref; So it is necessary to specify type of ref, isn't it?
/// Screen with scrollable widget.
class ScrollableScreen<T> extends HookConsumerWidget {
/// Creates a [ScrollableScreen].
const ScrollableScreen({
required this.provider,
super.key,
});
/// Provider of a controller with [PaginationMixin] for the [ScrollableScreen].
final AutoDisposeAsyncNotifierProvider<dynamic, PaginationState<T>> provider; Is it a proper way? If I change |
Beta Was this translation helpful? Give feedback.
-
Depends on what your mixin needs. Generally |
Beta Was this translation helpful? Give feedback.
-
Providers shouldn't be passed as parameter at all. So I would argue that's asking the wrong question. |
Beta Was this translation helpful? Give feedback.
-
to encapsulate paging loading widget,riverpod_paging_utils uses the mixin solution. riverpod_infinite_scroll use the StateNotifier solution |
Beta Was this translation helpful? Give feedback.
-
In continuation of the discussed in #1953
Hello!
I have made a mixin on
AutoDisposeAsyncNotifier
to reuse code in myAsyncNotifier
s with list pagination logics.It works well, when I am using
AsyncNotifier
with no additional arguments. But if there are arguments (similar tofamily
), generator createsBuildlessAutoDisposeAsyncNotifier
, not generalAutoDisposeAsyncNotifier
. So the mixin has class mismatch.This one works well:
And this one won't work because of
id
argument:The problem would be solved, if there's a possibility to make mixin on
BuildlessAutoDisposeAsyncNotifier
(which is only for internal use now), rather thanAutoDisposeAsyncNotifier
.So, is it possible to open
BuildlessAutoDisposeAsyncNotifier
for public consumption outside of 'riverpod_generator'? Or maybe here can be another solution?Beta Was this translation helpful? Give feedback.
All reactions