by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 22:13
    smrfs commented #422
  • 21:59
    feinstein opened #462
  • 20:20
    floyergilmour commented #422
  • 20:04
    floyergilmour commented #354
  • 19:14
    rrousselGit commented #461
  • 19:03
    egprojects edited #461
  • 19:01
    egprojects opened #461
  • May 24 16:23

    rrousselGit on master

    Add FAQ section for consuming p… Merge pull request #460 from Ki… (compare)

  • May 24 16:23
    rrousselGit closed #460
  • May 24 16:23
    rrousselGit closed #234
  • May 24 16:23
    rrousselGit commented #460
  • May 24 16:22
    codecov[bot] commented #460
  • May 24 16:21
    codecov[bot] commented #460
  • May 24 16:21
    codecov[bot] commented #460
  • May 24 16:20
    rrousselGit edited #460
  • May 24 16:19
    codecov[bot] commented #460
  • May 24 16:19
    codecov[bot] commented #460
  • May 24 16:12
    KieranCTaylor opened #460
  • May 24 15:48
    rrousselGit commented #234
  • May 24 15:44
    KieranCTaylor commented #234
Remi Rousselet
@rrousselGit
You can call Provider.of<T>(context, listen: false) in create
Rolly Peres
@RollyPeres
True, but isn't that too verbose compared to update ?? approach ?
Hadi
@haadinorouzi
The method 'dependOnInheritedWidgetOfExactType' was called on null.
dependOnInheritedWidgetOfExactType<_EffectiveTickerMode>()
this errors occur when using animation in statefulwidget
Ioana Alexandru
@IoanaAlexandru
Is there any way to mock provider methods, if I'm using a MultiProvider with the MaterialApp as its child?
Ioana Alexandru
@IoanaAlexandru
Added more details about my issue here: rrousselGit/provider#365
mimanx
@mimanx
Should I use ProxyProvider to provide the ThemeData? In Selector() I must create another BuildContext like builder: (_,__,___) => Builder(builder: (BuildContext context) => Container(color: Theme.of(context).primaryColor)) to use Theme, otherwise it will not be rebuilt when themedata change. Is there any better way?
seyyed hamid shojaeddin
@HamidShojaeddin_twitter
I have tried futureProvider with sqflite but I do not get quick update with futureProvider and I can not use simple provider with sqfilte
What is best way to save in sqflite and update simultaneously widgets with provider ?
Subven Malla
@SubvenMalla7
image.png
hello all i wanted to provide positional argument inside create of ChangeNotifierProxyProvider
How can i pass it like in update?
Remi Rousselet
@rrousselGit

@SubvenMalla7 It's considered "unsafe" inside create, as you won't have updates

If you insist on doing so, you can use the context object:

create: (context) => Whatever(Provider.of<Something>(context, listen: false)),
Subven Malla
@SubvenMalla7
@rrousselGit Thank you for your response ChangeNotifierProxyProvider has be updated previously builder only can be used and i only wanted to use builder how to do than in newer version. I have researched builder is changed to update but what about create? i am not getting it
Rakesh Kumar
@RakeshKumar9x_twitter
How we can maintain the selected item for multiple drop- downs inside a Row under ListView?
@All
Remi Rousselet
@rrousselGit
I don't understand the question
Richard Flosi
@richard-flosi
I think the question is about multi select for a dropdown. Are you representing multiple selected items in you state/provider layer? Should just be a matter of reflecting that in the UI. What trouble are you running into? How are you managing the list of selected items?
Julián
@Juliaandavid_twitter
Hi @rrousselGit, I'm introducing in provider library and I read about bad ways to manage providers, I want to ask you about this code if this is the best way to inject provider dependency. I dont know how to use create method actually. Thanks!
class App extends StatelessWidget {

  @override
  Widget build(BuildContext context) =>
      MultiProvider(
        providers: [
          ChangeNotifierProvider(
              create: (_) => AuthProvider()
          ),
          ProxyProvider<AuthProvider, UserProvider>(
            create: (context) => UserProvider(Provider.of<AuthProvider>(context, listen: false).user),
            update: (BuildContext context, AuthProvider auth, UserProvider user) => user ?? UserProvider(auth),
          ),
        ],
        child: MaterialApp(
          theme: lightTheme,
          initialRoute: '/',
          routes: Router.routes,
        ),
      );
}
Aseem Shrey
@LuD1161
Hi :wave:

Sorry to start the conversation with a question but I've spent a few days now understanding how this should be done and hence looking for answers in a variety of forum.
I've implemented Provider pattern in a simple Notes app.

Problem :

Data is loaded on the screen only when the app reloads or the screen gets rebuilt.

This is my note_list stateless widget which displays the notes :


class NoteList extends StatelessWidget {
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Note List"),
      ),
      body: getnoteListView(context),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return ChangeNotifierProvider(
              builder: (context) => NoteProvider(),
              child: NoteDetail(Note('', '', 2), 'Add Note'),
            );
          }));
        },
        tooltip: "Add Note",
        child: Icon(Icons.add),
      ),
    );
  }

  ListView getnoteListView(BuildContext context) {      // <---- the thing to be focused here
    final noteProvider = Provider.of<NoteProvider>(context);
    var noteList = noteProvider.noteList;
    var count = noteList.length;
    TextStyle titleStyle = Theme.of(context).textTheme.subhead;
    return ListView.builder(
      itemCount: count,
      itemBuilder: (BuildContext context, int index) {
        print(noteList[index].title);
        return Text(
          noteList[index].title,
          style: titleStyle,
        );
      },
    );
  }
}

And the NoteProvider.dart :

import 'package:flutter/material.dart';
import 'package:pass_list/models/note.dart';
import 'package:pass_list/utils/database_helper.dart';

// https://stackoverflow.com/a/56713184
class NoteProvider with ChangeNotifier {
  DatabaseHelper databaseHelper = DatabaseHelper();
  List<Note> _noteList = [];
  int count = 0;
  // get updateListView;

get noteList => _noteList;

  NoteProvider(){
    fetchNotes();
  }

  void setNoteList(notesList) {
     _noteList = notesList;
// notifyListeners(); <- this didn't work either
  }

  fetchNotes() async {
    await databaseHelper.initializeDatabase();
    List<Note> noteList = await databaseHelper.getNoteList();
    setNoteList(noteList);  
  }

  Future<int> updateNote(note) async{
    var result = await databaseHelper.updateNote(note);
    await fetchNotes();
    notifyListeners();
    return result;
  }

  Future<int> insertNote(note) async{
    var result =  await databaseHelper.insertNote(note);
    await fetchNotes();
    notifyListeners();
    return result;
  }

  Future<int> deleteNote(noteId) async{
    var result =  await databaseHelper.deleteNote(noteId);
    await fetchNotes();
    notifyListeners();
    return result;
  }
}

Here's the repo, in case you wish to run the app : Repo

Directory Structure :

lib
├── main.dart
├── models
│   └── note.dart
├── screens
│   ├── note_detail.dart
│   └── note_list.dart
└── utils
    ├── database_helper.dart
    └── NoteProvider.dart

Video of the problem : https://youtu.be/YrAVTum9P6E

Update :

Since in the constructor for noteProvider I've fetchNotes so maybe due to that, when the app is loaded it's being fetched and due to that I added in all other functions too. But that didn't end as expected and am still facing the error.

Help with design and best practices

Moreover it would be better if someone could point to me some resources like blog/actual code where I can see this implemented. That would be really awesome.

Thanks.

Fabian Johnson
@qilobit
:point_up: April 9, 2020 3:24 PM Try returning the notesList from the fetchNotes method and use FutureBuilder above the ListView
Rakesh Kumar
@RakeshKumar9x_twitter
image.png
Is there anyone can give the idea to make dialpad design on flutter without using any third-party library???
Rakesh Kumar
@RakeshKumar9x_twitter
Hi, is there anyone can tell, how to give width on PopupMenuItem on flutter?
I am able to give on height, it's taking their default padding that also not being removed
Alan Trope
@atrope

Hello Everyone, I am trying to use StreamProvider + Consumer in my Stream.

I am creating the controlleras:

final _mediaStreamController = StreamController<MediaDownloadProgress>.broadcast();

And then i am sending via Multiprovider to the children:
StreamProvider<MediaDownloadProgress>.value( value: _mediaStreamController.stream, updateShouldNotify: (p1, p2) => true;

In My Consumer/Selector i am Using like this:

Selector<MediaDownloadProgress, MediaDownloadProgress>( selector: (BuildContext context,MediaDownloadProgress progress) => progress, shouldRebuild: (prev, next) => true, builder: (context, progress, _) => print("INSIDE CONSUMER $progress"), );

My Downloads emits 90~100 events and the Stream receives all of them, but the consumer only roughly half.

I Debuged in the code and found out that the lost is happening between in the markNeedsNotifyDependents function of the inherited_provider in which provider does enter that function in all events, but it only enter build for half of it.

Is there something we can do so the Consumer/Selector receives all events?

Thanks

Remi Rousselet
@rrousselGit
No
This is expected. Builds are called only once or frame.
Alan Trope
@atrope
So there is no way i can listen to a stream and guarantee i will at least receive the last event?
this is something expected? i just made a simple example of 2 selectors to check numbers from 1 to 100 if they are odds or even, both selectors did not got the last event (number 99/100) and the second selector lagged behind
screenshot-1588699076967.jpg
Alan Trope
@atrope
and i have pages with 50 Selectors in the same Stream, so is Consumer/Selector not a good use case for that?
Alan Trope
@atrope
@rrousselGit
Alan Trope
@atrope
Ok, in my tests i realised the problem was/is the 16ms limit for setstate. The stream was receiving all events but "losing"them because of that limitation
Rakesh Kumar
@RakeshKumar9x_twitter
@rrousselGit , Is there any way to lock the method. Only one thread can execute at one time. One request can be put into a queue. Something like that
Remi Rousselet
@rrousselGit
@RakeshKumar9x_twitter Could you elaborate?
Rakesh Kumar
@RakeshKumar9x_twitter

@RakeshKumar9x_twitter Could you elaborate?

I am inserting the data into a database on flutter. As one insertion request already executing then another request taking place. Because both requests having the same data

I am just trying to like to lock the method until it's done. One process being executed another process or request can be put into queue
Diego Tori
@diegotori
@rrousselGit Quick question: Suppose you have a MultiProvider and you want to want to add a nested MultiProvider within the list of providers. How would something like that look like?
Marc
@mscherer82
Hi, is it possible to use a ChangeNotifierProvider in side a ListView?
Marc
@mscherer82
I got the error message A Model was used after being disposed. E/flutter (10215): Once you have called dispose() on a Model, it can no longer be used. when trying to do this.
virgil246
@virgil246
Is there any example for futureprovider?
How to init Value inside of Provider with an async function
I need to get api query key when app start and keep it until app closed is a good situation to use provider?
I will get api query key with http request
Remi Rousselet
@rrousselGit
Use FutureProvider
virgil246
@virgil246
Use FutureProvider
Thx I figure out the solution
Adis Durakovic
@ad-on-is_gitlab
May I ask the difference between Provider<Foo>(create: (context) => Foo(api: Provider.of<Api>(context, listen: false))) and ProxyProvider<Api, Foo>()
Sameer Kashyap
@Sameerkash

Hello, I'm having a problem with my ChangeNotifier, I have this piece of code in my model

  class Comment with ChangeNotifiere{ ...

  RequestState _state = RequestState.initial;
  RequestState get state => _state;

  void setState(RequestState state) {
    _state = state;
    notifyListeners();

  .... }

And this is my API call method

  ///Get all comments for a particular review
  Future<void> getComments(
    CommentNotifer commentNotifer, String reviewId) async {
    if (reviewId != null) {
      try {

        commentNotifer.setState(RequestState.loading);
        _startComment = 0;

var response = await sendGet("/api/comment/readLimitedReviewComment/$reviewId?start=$_start&limit=10");
    ]if (response != nulll) 
    { 
    var comments = CommentResponse.fromJson(response);
    commentNotifer.setState(RequestState.hasData);
    }

     ....  }

I want to set the RequestConnection to loading before I make the call, but I get

setState() or markNeedsBuild()
This _InheritedProviderScope< CommentNotifer > widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built.

this error, I understand what I'm doing wrong, I'm marking the widget to build when its already in the process of building, as I call the API in the

initState ()

method of my widget but what I don't understand is how to call this the right way. could you help me? @rrousselGit