mirror of
https://github.com/rrousselGit/riverpod.git
synced 2025-08-26 10:35:32 +08:00
Allow all providers to be scoped (#542)
This commit is contained in:
@ -278,7 +278,9 @@ abstract class TagTheme with _$TagTheme {
|
||||
}) = _TagTheme;
|
||||
}
|
||||
|
||||
final tagThemeProvider = ScopedProvider<TagTheme>(null);
|
||||
final tagThemeProvider = Provider<TagTheme>((ref) {
|
||||
throw UnimplementedError();
|
||||
});
|
||||
|
||||
class Tag extends HookConsumerWidget {
|
||||
const Tag({
|
||||
|
@ -103,7 +103,9 @@ abstract class QuestionTheme with _$QuestionTheme {
|
||||
}) = _QuestionTheme;
|
||||
}
|
||||
|
||||
final questionThemeProvider = ScopedProvider<QuestionTheme>(null);
|
||||
final questionThemeProvider = Provider<QuestionTheme>((ref) {
|
||||
throw UnimplementedError();
|
||||
});
|
||||
|
||||
class MyHomePage extends HookConsumerWidget {
|
||||
const MyHomePage({Key? key}) : super(key: key);
|
||||
@ -140,10 +142,11 @@ class MyHomePage extends HookConsumerWidget {
|
||||
itemBuilder: (context, index) {
|
||||
return ProviderScope(
|
||||
overrides: [
|
||||
currentQuestion.overrideAs((watch) {
|
||||
return watch(paginatedQuestionsProvider(index ~/ 50))
|
||||
.whenData((page) => page.items[index % 50]);
|
||||
}),
|
||||
currentQuestion.overrideWithValue(
|
||||
ref
|
||||
.watch(paginatedQuestionsProvider(index ~/ 50))
|
||||
.whenData((page) => page.items[index % 50]),
|
||||
),
|
||||
],
|
||||
child: const QuestionItem(),
|
||||
);
|
||||
@ -163,7 +166,9 @@ class MyHomePage extends HookConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
final currentQuestion = ScopedProvider<AsyncValue<Question>>(null);
|
||||
final currentQuestion = Provider<AsyncValue<Question>>((ref) {
|
||||
throw UnimplementedError();
|
||||
});
|
||||
|
||||
class QuestionItem extends HookConsumerWidget {
|
||||
const QuestionItem({Key? key}) : super(key: key);
|
||||
|
Reference in New Issue
Block a user