Questions tagged [flutter-provider]

For questions relating to the "Provider" package for the Flutter framework. Use this tag in combination with the general [flutter] tag. If your question applies to Flutter more generally, use the [flutter] tag only.

This tag should be used for any questions regarding the provider package for the framework.

The provider is a wrapper around InheritedWidget to make them easier to use and more reusable.

Provider uses InheritedWidget's to provide dependency injection functionality for state management in Flutter applications.

To get started, one can read through the README on GitHub, i.e. on the official GitHub page for the provider package.

1487 questions
13
votes
2 answers

RiverPod - How to await using FutureProvider on AsyncValue not in widget

I need to get 1 field 1 time from Firebase Cloud Firestore. How do I accomplish this with providers outside of Widget build? Below are my combined providers. appStartupProvider is a FutureProvider and I want to get the bool value from this 1 field…
Zelf
  • 1,723
  • 2
  • 23
  • 40
11
votes
2 answers

How to use a riverpod family provider without passing parameter

Is there a way to access an instance of a provided ".family" change notifier (which has already been instantiated, passing the right parameters) without passing the parameters again? IN PROVIDER When you create a provider of a ChangeNotifier (which…
Prince
  • 245
  • 4
  • 9
11
votes
2 answers

Provider .read() vs .watch()

I just updated my flutter_bloc library to 6.1.1 in which states: bloc' is deprecated and shouldn't be used. Use context.read or context.watch instead. Will be removed in v7.0.0. Try replacing the use of the deprecated member with the…
Georgios
  • 861
  • 2
  • 12
  • 30
11
votes
1 answer

Flutter Riverpod context.read vs Provider in the build method

In the Riverpod documentation it says: That's where context.read(myProvider) is a solution. Using it, we could refactor our previous code to: @override Widget build(BuildContext context) { return RaisedButton( onPressed: () =>…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
11
votes
2 answers

Cannot find Widgets in test inside of Consumer Widget of Provider

I created the following Flutter test for my widget testWidgets("", (WidgetTester tester) async { await tester.pumpWidget( ChangeNotifierProvider( create: (context) => SettingsViewProvider(), …
Max Weber
  • 1,081
  • 11
  • 21
11
votes
4 answers

How to call method at App start if I am using provider?

I want to complete get request to server to get data for my app at it start. I read several topics that describe how to run method after building widgets. But all of them are describe situations when provider is not using. And I am not sure that…
Dmitry Bubnenkov
  • 9,415
  • 19
  • 85
  • 145
10
votes
3 answers

Flutter problem with finding provider context

I have a problem with Flutter Provider pattern. After user is redirected to a new screen, the provider could not be found. Following my previous question (Could not find the correct provider above this widget) I wrote this code: class NewRoute…
harunB10
  • 4,823
  • 15
  • 63
  • 107
10
votes
3 answers

How to use flutter provider in a statefulWidget?

I am using flutter_provider for state management. I want to load some items on page(statefulwidget) load from Api. I am showing a loader on page start and want to show the items once they are fetched. PlayList.dart - class Playlist extends…
Jay Surya
  • 540
  • 1
  • 8
  • 18
9
votes
1 answer

How to scope providers on several widgets without putting the provider on a root widget in flutter

I'm working on a simple demo where the user logs in, sees a list of items, clicks on an item, and then sees its details. These are 3 screens but let's say two flows where one deals with login and the other with items. I'm managing my state using…
Spidey
  • 894
  • 1
  • 13
  • 29
9
votes
1 answer

Flutter 'No Overlay widget exists above EditableText' error when using Provider

Hey I've got a MultiProvider setup, and it's now throwing this error when tapping on a TextField whereas it didn't before I implemented the multi-provider: No Overlay widget exists above EditableText The error text does not give any helpful…
9
votes
1 answer

Persist Provider data across multiple pages not working

I'm using Provider in my flutter app, and when I go to a new page, the data provided to the Provider at page 1 is not accessible in page 2. The way I understood the way Provider works, was that there is a central place where one stores all the data,…
Jessica
  • 9,379
  • 14
  • 65
  • 136
9
votes
2 answers

How to get data from the FutureProvider in flutter

I'm trying to implement local database support in my flutter app which is being managed using Provider, now I want to make the retrieving of data obey the state management pattern, but I've been failing to. I've tried to make a traditional Provider…
Basel Abuhadrous
  • 1,444
  • 1
  • 14
  • 30
9
votes
1 answer

Flutter : Is provider an alternative to the BLoC pattern?

I know that BLoC in flutter acts like the viewmodel layer in android's MVVM, so the data does not gets fetched again and again upon configuration changes (for ex: change in screen orientation). I am confused if provider replaces the functionality…
curiousgeek
  • 903
  • 11
  • 18
8
votes
2 answers

How to mock Socket.io client in Flutter tests

I'm using socket_io_client v0.9.12 in my flutter app (still not using null safety). I am creating a socket connection with my back-end server when the app starts and allow child widgets to access it using a provider. I am trying to start creating…
Eranga Heshan
  • 5,133
  • 4
  • 25
  • 48
8
votes
1 answer

Flutter could not find the correct Provider after navigating to different route

I'm using bloc to handle the state of a signup form. But I get the error: Error: Could not find the correct Provider above this BlocBuilder Widget. As you can see in the error I do use the bloc…
JonasLevin
  • 1,592
  • 1
  • 20
  • 50