根据条件更新提供者侦听器

时间:2021-03-26 19:53:01

标签: flutter dart riverpod

我有两个提供者,一个在听另一个:

final counterStepProvider = Provider<AsyncValue<int>>(
        (ref) => ref.watch(counterProvider.state).whenData((double value) => value.floor()));

final counterProvider = StateNotifierProvider<CounterState>((ref) => CounterState());

class CounterState extends StateNotifier<AsyncValue<double>> {

CounterState(this.minCounter, this.maxCounter) : super(AsyncLoading()) {
    state = AsyncData(0);
  }

  set counter(double counter) {
    state = AsyncData(counter);
  }
}

问题在于,即使状态具有相同的值,counterStepProvider 也会始终更新其侦听器。有没有办法只在 value.floor != state 时更新?

0 个答案:

没有答案