Coder Social home page Coder Social logo

ProviderListener missing events about riverpod HOT 12 CLOSED

tbm98 avatar tbm98 commented on August 21, 2024
ProviderListener missing events

from riverpod.

Comments (12)

rrousselGit avatar rrousselGit commented on August 21, 2024 2

The thing is, Providers voluntarily do not call listeners immediately on change

This is for performance and maintainability reasons.

So you're better off with a custom WhateverListener for special objects

from riverpod.

tbm98 avatar tbm98 commented on August 21, 2024

In the documentation.
Even if a provider changes many times in a quick succession, onChange will be called only once, at the end of the frame.
but I think it should triggers onChange if state is changed instead of call only once at the end of the frame

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024

What's the purpose?

from riverpod.

tbm98 avatar tbm98 commented on August 21, 2024

In a task, maybe something I want to pass more than one event to UI handle.
an example: loading dialog is showing and my http request done, then I want to dismisDialog and show snackbar for result success or fail.

from riverpod.

tbm98 avatar tbm98 commented on August 21, 2024

so still can pass successEvent to UI do both dismisDialog and showSnackbar but I think it will be more flexible if it is managed from providers.

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024

Maybe you shouldn't use StateProvider and instead use StateNotifierProvider with a custom StateNotifier

from riverpod.

tbm98 avatar tbm98 commented on August 21, 2024

What is that better than StateNotifier if I use StateNotifierProvider ?

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024

Actually, I'm not sure what you're trying to accomplish by writing:

context.read(eventProvider).state = LoadingEvent();
context.read(eventProvider).state = ShowSnackbarEvent();

StateNotifier is not an event queue, nor are providers.

Why not write showDialog/Navigator.pop directly inside the onPressed?

from riverpod.

tbm98 avatar tbm98 commented on August 21, 2024

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024

Maybe do context.read(eventProvider).addListener(...)

from riverpod.

tbm98 avatar tbm98 commented on August 21, 2024

I think addListener will be difficult to use in StatelessWidget or HookWidget because it should only be called once. So ProviderListener was born as a solution to the above problem and I think it should work like what addListener does as well.

from riverpod.

tbm98 avatar tbm98 commented on August 21, 2024

Yes. maybe I need another way to solve it.
Thanks !

from riverpod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.