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
0
votes
0 answers

How to add provider to second widget tree?

I am try follow this answer for add provider to second widget tree (so can call provider from function). But I get error: [VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: Error: Could not find the correct Provider above this Page…
FlutterFirebase
  • 2,163
  • 6
  • 28
  • 60
0
votes
1 answer

ChangeNotifier dispose model too early

I am use Firestore transaction for avoid race condition of add more than 1 user to chat. If transaction timeout, I show error dialog. But when I move this logic to Model2 with ChangeNotifier (and Provider) it now show error: Unhandled Exception: A…
0
votes
1 answer

Setter error using ChangeNotifierProxyProvider

I am try pass string from Model1 to Model2 use ChangeNotifierProxyProvider, but it give error: No setter named ‘string’ in class ‘Model2’ Model1: class Model1 extends ChangeNotifier { ... final String string =…
FlutterFirebase
  • 2,163
  • 6
  • 28
  • 60
0
votes
1 answer

Why model cannot access another model using provider?

I want do this (not possible): class Model1 extends ChangeNotifier { ... final List items = []; } class Model2 extends ChangeNotifier { void performOperation() { //Access items from Model1 here final newItems =…
0
votes
1 answer

Should use Provider if I have few classes for processing data?

I read docs, and looked a lot of examples, but still can't understand should I use Provider if I need access to data in several classes. The main problem -- context that do not exists outside widgets. So probably I do not understand conception of…
Dmitry Bubnenkov
  • 9,415
  • 19
  • 85
  • 145
0
votes
1 answer

Provider in init method of main.dart

Can I use provider in init method of the main.dart file ? I tried using the SchedulerBinding.instance.addPostFrameCallback method as a callback but I get exception. import 'package:flutter/material.dart'; import…
gopal
  • 335
  • 1
  • 4
  • 11
0
votes
1 answer

Is there a ChangeNotifierList?

Is there a List class that implements ChangeNotifier? Basically if anything is added to the list or the list is rearranged it will call notifyListeners?
dakamojo
  • 1,839
  • 5
  • 21
  • 35
0
votes
2 answers

Allow distinction between providers

I am building an app with flutter and the provider pattern. I have particular one ViewModel, that gets provided with Provider.of(context). class HomeScreen extends StatelessWidget { @override Widget build(BuildContext…
thehayro
  • 1,516
  • 2
  • 16
  • 28
0
votes
1 answer

How can I change the colour of the border of the selected tile in Flutter?

I have list of tile that shows list of available flights. I want to change the colour of the border of the selected tile. At the moment, it changes the colour of all tiles instead of only the selected one. final flightState =…
Daniel
  • 478
  • 3
  • 16
  • 32
0
votes
1 answer

Flutter state management issue

My problem is related to the provider pattern/library. I have created some state classes as follows (ive replaced content/var names to try and keep it simple) class State1 with ChangeNotifier{ String _s; set s(String newS){ _s = newS; …
ebg11
  • 906
  • 1
  • 12
  • 33
0
votes
1 answer

Flutter: The method '[]' was called on null. StreamProvider

I have a StreamProvider reading from Firebase Firestore which works fine when there is data in the document, but if there isn't a document/collection created yet, i get the error "The method '[]' was called on null." It is just reading a number from…
Chris
  • 165
  • 4
  • 16
0
votes
1 answer

How to update specific widget after got response from listening socket.on?

I have 2 separate class, Class Socketio and Class HomePage. I want update HomePage after socket.on in class Socketio got response, how to update widget in HomePage from class Socketio? I try using provider library but didn't how to use Listenable…
moanrisy
  • 109
  • 1
  • 12
0
votes
1 answer

Cound not find the correct Provider above this consumer Widget

I'm trying use multiprovider from library Provider. But it's not working because it's can't find correct provider althought the upper widget before material is MultiProvider. I Already try to import anything but it's still not working class…
moanrisy
  • 109
  • 1
  • 12
0
votes
2 answers

Flutter: BLoC package - bloc provider

I'm using this package: https://pub.dartlang.org/packages/bloc . I have 2 views: In the first one I display a list of elements using "bloc1" and, trough a FloatingActionButton, I can navigate to a second screen that uses "bloc2". In this second…
Little Monkey
  • 5,395
  • 14
  • 45
  • 83
-1
votes
1 answer

flutter riverpod watch nested future provider inside the build method, that each one trigger if the previous one has data?

if (ref.read(connectivityStatusProviders)) { _goBackToHome(ref: ref, isUserCanceled: false); } void _goBackToHome( {required WidgetRef ref, required bool isUserCanceled}) async…
Mo_Ho
  • 9
  • 2