Questions tagged [flutter-riverpod]

166 questions
1
vote
2 answers

Why Riverpod provider goes into the loading state when there's already value?

Minimum reproducible code: class FooPage extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final asyncValue = ref.watch(provider1); print('loading: ${asyncValue.isLoading}, value:…
iDecode
  • 22,623
  • 19
  • 99
  • 186
1
vote
1 answer

flutter_riverpod - Accessing a `Ref` when `context` is available

I'm in the process of migrating my app to use flutter_riverpod package. At the moment, my app is using provider package to manage/deal with app state. I have a lot of static methods inside multiple utility classes that take a BuildContext as input.…
zepolyerf
  • 1,098
  • 3
  • 16
  • 35
1
vote
1 answer

How can I update state notifier(riverpod) from Go router state.params

The pagebuilder in GoRoute has the the only place I can grab the state.params, I want to update my StateNotifier when the route changes if it is different. final LibraryRoutes = Provider((ref) { return ShellRoute( navigatorKey:…
1
vote
1 answer

How to solve the infinite loop problem in Flutter?

I get the following error in the terminal (not the debug console because I'm running flutter run -d chrome --web-hostname localhost --web-port 7357 command): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY…
My Car
  • 4,198
  • 5
  • 17
  • 50
1
vote
1 answer

How to change provider state within itself?

Minimal reproducible code: final provider = StateProvider((ref) { Timer? _timer; ref.listenSelf((_, flag) { if (!flag) { _timer = Timer(Duration(seconds: 5), () { ref.read(this).state = true; }); } }); //…
iDecode
  • 22,623
  • 19
  • 99
  • 186
1
vote
0 answers

using ChangeNotifier to add items into empty list

I already have data stored on firestore , but now i'd like to add this data into an empty list using ChangeNotifier , similar to this example -https://docs.flutter.dev/development/data-and-backend/state-mgmt/simple . so below i'd like to add data…
1
vote
1 answer

Flutter/Riverpod with service and respository - how to

I am building my first RiverPod based Flutter app, and I'm trying to understand how RiverPod works with the service and repository pattern. I have a repository class that owns the task of handling interactions with a particular storage API, in this…
user2868835
  • 1,250
  • 3
  • 19
  • 33
1
vote
1 answer

How do I fix the error about a widget being unmounted so the State no longer has a context in Flutter?

I get an error. Here is the debug console: ════════ Exception caught by scheduler library ═════════════════════════════════ This widget has been unmounted, so the State no longer has a context (and should be considered…
My Car
  • 4,198
  • 5
  • 17
  • 50
1
vote
3 answers

Is there a way to call a method of another class in Flutter?

I am passing the method as follows But it is very complicated. I want to call methods directly without passing methods. Is there any way to do that? class Parent extends StatelessWidget { const Parent({Key? key}) : super(key: key); @override …
Ganessa
  • 782
  • 2
  • 7
  • 24
1
vote
2 answers

Riverpod 2.0: override with value does not exist anymore

I have a provider named gameControllerProvider extends with ChangeNotifier, I initialize it first throw UnimplementedError. final gameControllerProvider = ChangeNotifierProvider((ref) => throw UnimplementedError()); In my…
1
vote
0 answers

Flutter riverpod listen to ChangeNotifierProvider

In this code i have a simple riverpod provider which that should connect and listen to events. here connect to pusher work fine and i can receive data from that and printing in logcat, but i can't listen to that in defined provider into screen final…
DolDurma
  • 15,753
  • 51
  • 198
  • 377
1
vote
1 answer

What should build() return after it realizes a need for a state change?

I think I'm missing something about the Riverpod philosophy. I'm keeping all my game state in a ChangeNotifier, including the .stage which can be "start", "playing", "winning", etc: final ChangeNotifierProvider gameStateProvider = …
Michael Gundlach
  • 106,555
  • 11
  • 37
  • 41
1
vote
3 answers

Riverpod: Is it wrong to refer in onPressed to a provider obtained earlier by ref.watch?

Riverpod docs say to use ref.read in callbacks like a button's onPressed, since you must not use ref.watch there. Is it OK to do something like this? build(context, ref) { // Use ref.watch ahead of time, because I refer to p all over // the…
Michael Gundlach
  • 106,555
  • 11
  • 37
  • 41
1
vote
2 answers

using ref.read inside build method for StateControllers

As per the Riverpod documentation, asynchronously we use ref.read such as inside a function and for synchronous code, we use ref.watch such as inside the build method. Once I press a button, the function with ref.read will fire up and it will be for…
Anmol Singh
  • 393
  • 3
  • 16
1
vote
3 answers

How to get the previous value of a provider in Riverpod?

The code below takes user input, and prints it in the upper case after a delay of 1s. Minimal reproducible code: class FooPage extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final asyncValue =…
iDecode
  • 22,623
  • 19
  • 99
  • 186