4
@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?

zbk
  • 189
  • 6
  • Is this inside a Stateful widget? – Dani3le_ Apr 20 '22 at 12:36
  • 1
    @Dani3le_ No. I use ConsumerWidget instead of that. – zbk Apr 20 '22 at 12:42
  • Hi @hbk, please share your code for the `StateNotifier` class that you wrote. – Josteve Apr 21 '22 at 06:12
  • @Josteve Thank your comments. I resolved the problem using StatefulBuilder. But, I have trouble with the parent widget is not rebuild after closed BottomSheet. Should I use StatefulBuilder for this problem too? Do you know a better way to resolve it? – zbk Apr 21 '22 at 07:52
  • @zbk, How did you resolve it by using StatefulBuilder together with Riverpod? – Theo Jul 22 '23 at 18:18

1 Answers1

0

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(...);
});
Ayoub Boumzebra
  • 3,885
  • 3
  • 21
  • 37
  • I used consumer inside bottom sheet. its not working, value is updating from log but not reflecting in bottom sheet. Basically i want to show progressBar in bottomsheet. value is coming from sockets and i am reading values in statenotifier – Hadi Khan Aug 01 '23 at 06:53