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
8
votes
1 answer

How to correctly fetch APIs using Provider in Flutter

I'm currently dealing with a problem where I need some data from an API to show it into my widgets. I've following some Provider architecture pattern, where you setState two times: 1- When data is being fetched 2- When data is already fetched So the…
Nikssj_
  • 187
  • 2
  • 3
  • 11
8
votes
1 answer

A Provider was used after being disposed - Multiprovider

After I added the dependency of ProfileLogic to LocationLogic I get the following error when the app starts: I/flutter (14674): A LocationLogic was used after being disposed. I/flutter (14674): Once you have called dispose() on a LocationLogic, it…
Felipe Augusto
  • 7,733
  • 10
  • 39
  • 73
8
votes
1 answer

How to know what triggered my Flutter widget rebuilds

I've seen many questions around asking why one widgets unnecessarily rebuilds, but I'm looking for a method to understand what triggered them. So I put a breakpoint on a view widget and I got quite a huge stack (cropped - it was 5 times…
Hugo H
  • 6,029
  • 5
  • 37
  • 57
8
votes
1 answer

StreamProvider not updating state

I am trying to use a StreamProvider (from this awesome package), but I've been struggling to get a particular stream to work. I create a StreamController which I use to add data to its Stream via its Sink. All of this seems to be working fine.…
Bram Vanbilsen
  • 5,763
  • 12
  • 51
  • 84
8
votes
4 answers

How can I Initialize provider?

I have implemented Provider for state management in my app. Now, I need to add some data in the class once the screen is loaded. How I can achieve this? stepInfo.addToList = new VaccStep(); // Need to call it one time once screen is loaded. I have…
Ahmed Abosrie
  • 237
  • 1
  • 5
  • 16
7
votes
1 answer

How should I manage the state of a large model in Flutter?

I'm writing my first Flutter app and struggling with the variety of state management solutions. I decided to start with Provider, but I'm thinking about switching over to BLoC. So far most of the examples I've found are limited to relatively…
Mark R
  • 341
  • 3
  • 10
7
votes
0 answers

Using provider pattern with database in flutter

I am new to flutter and especially provider pattern. I went through the documentation, examples and some tutorials for the provider pattern statemanagement and i am trying to implement it in one of my projects. I am developing a personal expenses…
irshukhan
  • 169
  • 2
  • 2
  • 12
7
votes
3 answers

Error: Type 'SingleChildCloneableWidget' not found in Provider package

I updated Provider. Now it's not working lib/di/global_providers.dart:13:6: Error: Type 'SingleChildCloneableWidget' not found. List globalProviders = [ ^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/di/global_providers.dart:18:6: Error: Type…
BIS Tech
  • 17,000
  • 12
  • 99
  • 148
7
votes
4 answers

ChangeNotifier mounted equivalent?

I am extract some logic from Stateful Widget to Provider with ChangeNotifier: class Model extends ChangeNotifier {...} In my Stateful Widget I have: if (mounted) { setState(() {}); } How I can check if Widget is mounted in Model? For example how…
FlutterFirebase
  • 2,163
  • 6
  • 28
  • 60
7
votes
2 answers

"setState() or markNeedsBuild() called during build" error trying to push a replacement in Navigator inside a Consumer widget (provider package)

This week I've began developing in flutter and i'm not able to solve this problem. I'm building a login page that calls an API to login and after redirects to an homepage. This is the exception generated by Navigator.pushReplacement in the first…
Davide Bicego
  • 562
  • 2
  • 6
  • 24
7
votes
2 answers

Error when adding provider package to flutter web project

I tried to add the provider package to my flutter web project and got the following error: Because every version of provider depends on flutter any from sdk which is >forbidden, provider is forbidden. So, because WebApplication depends on…
LP Square
  • 927
  • 1
  • 10
  • 17
6
votes
5 answers

flutter share received pusher data between screens using Riverpod

In our system we used Pusher on both of our Admin Panel and mobile application, in flutter i want to wrap whole application screens with Pusher and Riverpod and using providers with Hook widget in screens, that means i want to implement Pusher in…
DolDurma
  • 15,753
  • 51
  • 198
  • 377
6
votes
3 answers

Flutter auto_route | How do I wrap a route with BlocProvider?

So, I'm using the auto_route package for navigation in my app and flutter_bloc for state management. When I was using the old Navigator, I could just wrap a route with a BlocProvider. For example: class Router { static Route
IncorrectMouse
  • 179
  • 1
  • 9
6
votes
2 answers

Flutter: Get Provider if exists otherwise return null instead of exception

When we use BlocProvider.of(context) to access Bloc object, it returns an exception if no OrderBloc exists on ancestor widgets of current context. Returned exceptions as follows: No ancestor could be found starting from the context that…
Siamak S
  • 163
  • 9
6
votes
1 answer

How do you combine 2 Riverpod StreamProviders where 1 stream depends on the data from another stream?

Sometimes I think I'm getting the logic of providers and then I get stumped for hours trying to do something like below. I need to get a List of connection id's from a firestore collectionsstream. Easy. However, I need to feed this streaming list of…
Zelf
  • 1,723
  • 2
  • 23
  • 40