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
6
votes
3 answers

How to maintain Firebase Authentication after refresh with Flutter web?

I am using the authStateChanges stream from Firebase with flutter. I have two views, one for mobile and the another one for a web application. I want to redirect the user to the SignIn screen if he is not connected, logged in or authenticated. At…
6
votes
2 answers

Unhandled Exception: A ChangeNotifier was used after being disposed

I'm getting this error message: Unhandled Exception: A ModeManager was used after being disposed. I'm using ChangeNotifier (class ModeManager) together with ChangeNotifierProvider. Build method, where I create Provider looks like…
cavargov
  • 415
  • 5
  • 6
6
votes
1 answer

Flutter: StreamProvider with onAuthStateChanged always returns null as a first value

I'm trying to create a simple navigation according to auth state to Firebase, but for some reason Provider.of(context) always returns null as a first value in the widget build method. So my app always navigates to auth screen and…
6
votes
1 answer

Do you have to manually dispose streams from a streamprovider in Flutter?

I can't find this in the official documentation for the provider package, does streamprovider automatically handle disposing of streams they are providing or do you have to do this manually? If so, what is the best practice of where to dispose a…
John
  • 2,551
  • 3
  • 17
  • 29
6
votes
2 answers

getter was called on null when using provider in flutter

I am making a flutter app using provider pattern. And I am getting null error when I launch my app. button_data.dart goes like this. class ButtonData extends ChangeNotifier { List
Brooklyn Lee
  • 369
  • 2
  • 6
  • 15
6
votes
1 answer

How to properly reuse a Provider in Flutter

So I have this ChangeNotifierProvider high in my widget tree as I am seeing many children widgets to listen to its value. What I am currently doing is that I pass down the Provider.of(context) object from the parent widget into it's children via…
AverageCoder
  • 321
  • 6
  • 15
6
votes
2 answers

Flutter Provider doesn't rebuild widget

here's a piece of my code, but please read the question before jumping to conclusions: class RescheduleCard extends StatelessWidget { @override Widget build(BuildContext context)=> Consumer( builder: (context, appSnapshot, _)=> …
Francesco Iapicca
  • 2,618
  • 5
  • 40
  • 85
6
votes
3 answers

BLoC: how to pass it?

I would like to know the best way to pass the bloc. I read about the bloc providers, but what`s the difference between using them and just passing the bloc in the constructor like: ExampleView X = ExampleView(bloc,...) Actually I find this way…
Little Monkey
  • 5,395
  • 14
  • 45
  • 83
5
votes
2 answers

building a countdown clock inside a provider package change notifier

I have built a working countdown clock that displays the time remaining in the format, hours:minutes:senconds. inside a stateful widget. that uses a fullscreen inkwell to start and stop it. What I want to do is transfer this code to a change…
Nomad09
  • 161
  • 8
5
votes
1 answer

How to handle complex state with Riverpods StateNotifierProvider

I have a very big, complex app with lots of pages with input forms with lots of fields (texts, date-selection, combo-boxes,...), so the state is rather big. I'm switching from Provider to Riverpod, and the proposed way for state management seems to…
SouthbayDev
  • 698
  • 5
  • 10
5
votes
1 answer

Provider with GridView Builder

I am making an online store where there is a discount section and product categories on the mvvm architecture, the goal is to change the quantity of the added product to the cart, everything works except that the quantity changes for all products,…
Vasya2014
  • 203
  • 1
  • 5
  • 25
5
votes
2 answers

Null Check Operator used on a null value due to provider class

I'm getting the 'null check operator used on a null value' when I try to access specific screens. I blocked out my 'user_provider' custom class as well as parts of the code where it's used and it displays normally (no red screen) but without those…
5
votes
1 answer

Updating and animating an AnimatedList with Provider in Flutter

I'm able to successfully animate an AnimatedList's contents in Flutter when the list data is stored in the same component that owns the list widget (i.e., there's no rebuild happening when there's changes to the list data). I run into issues when I…
sleighty
  • 895
  • 9
  • 29
5
votes
1 answer

How can I check to see if provided class exists

I am using Provider package in my flutter app. I am conditionally providing a ChangeNotifier class using provider. A subsequent build method down the tree wants to check to see if the class exists, and it is not a failure case if it doesn't. How can…
Scorb
  • 1,654
  • 13
  • 70
  • 144
5
votes
1 answer

How to initialize stateProvider from constructor in RiverPod

Basically, I want to set the initial constructor value to StateProvider so I can use it in its child widgets. final stateProvider = StateProvider((ref) => "default"); class ExampleWidget extends ConsumerWidget { ExampleWidget({required String…
Kartik Garasia
  • 1,324
  • 1
  • 18
  • 27