Raw<T> typedef
Raw<T> = T
An annotation for marking a value type as "should not be handled by Riverpod".
This is a type-alias to T
, and has no runtime effect. It is only used
as metadata for the code-generator/linter.
This serves two purposes:
-
It enables a provider to return a Future/Stream without having the provider converting it into an AsyncValue.
@riverpod Raw<Future<int>> myProvider(...) async => ...; ... // returns a Future<int> instead of AsyncValue<int> Future<int> value = ref.watch(myProvider);
-
It can silence the linter when a provider returns a value that is otherwise not supported, such as Flutter's
ChangeNotifier
:// Will not trigger the "unsupported return type" lint @riverpod Raw<MyChangeNotifier> myProvider(...) => MyChangeNotifier();
The typedef can be used at various places within the return type declaration.
For example, a valid return type is Future<Raw<ChangeNotifier>>
.
This way, Riverpod will convert the Future into an AsyncValue, and
the usage of ChangeNotifier
will not trigger the linter:
@riverpod
Future<Raw<ChangeNotifier>> myProvider(...) async => ...;
...
AsyncValue<ChangeNotifier> value = ref.watch(myProvider);
Implementation
typedef Raw<T> = T;