Reputation: 249
@override
Widget build(BuildContext context, WidgetRef ref) {
final provider = counterNotifierProviders(Counter.initialize());
final counter = ref.watch(provider);
return Scaffold(
body: ElevatedButton(
onPressed: () => showModalBottomSheet<void>(
context: context,
builder: (context) {
return Column(
children: [
Text(counter.count),
TextButton(child: 'Add' onPressed: () => ref.read(provider.notifier).add()),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Text(counter.count)
is not updated. But, I know counter.count
was updating from log.
How I can resolve that problem?
Upvotes: 5
Views: 2117
Reputation: 5023
You can solve your problem by using Consumer to use its ref and rebuild the widget for you:
Consumer(
builder: (BuildContext context, WidgetRef ref, Widget? child) {
return Scaffold(...);
});
Upvotes: 0