English 中文(简体)
河流提供者在改变听力提供者的状况后被毁。
原标题:Riverpod Provider is destroyed after altering the state of a listened provider

在一个烟雾中,一把火库的订单清单打上了一张,但是,在德国马克,客户可以按照他们的愿望,过滤这些命令,以便这些受压力的芯片对清单进行过滤,并在德国马克显示。

为此,Im利用许多河流运输供应商,一个负责从控制器(从存放处)收集原始清单,另一个负责保存选定的标签,另一个负责利用后来的供应商保存过滤清单,核对图像以更好地说明。

我花了很多小时的时间,在挑选情报和情报部的标签时,要找到过滤名单,而没有任何工作。 我对这一局势抱歉?

过滤记录.dart提供方负责数据检索

@Riverpod(keepAlive: true)
FutureOr<List<Records>> recordListFiltered(RecordListFilteredRef ref) async {
  print( init: recordListFiltered );
  //lista de todos los records
  final recordsList = await ref.watch(cajaControllerProvider.future);
  //set de etiquetas seleccionadas
  final selectedEtiquetas = ref.watch(etiquetaSelecProvider);

  print( la varibale de etiquetas del provider: $selectedEtiquetas );

  ref.onAddListener(() => print( onAddListener: recordListFiltered ));
  ref.onRemoveListener(() => print( onRemoveListener: recordListFiltered ));
  ref.onDispose(() => print( dispose: recordListFiltered ));
  ref.onCancel(() => print( onCancel: recordListFiltered ));

  final List<Records> updatedList = recordsList.where((element) => !selectedEtiquetas.contains(element)).toList();
  return updatedList;

}

etiqueta_selec.dart provider in charge of storing the selected tags from the UI

import  package:riverpod_annotation/riverpod_annotation.dart ;
import  ../../../../models/etiquetas_model.dart ;

part  etiqueta_selec.g.dart ;

@Riverpod(keepAlive: true)
class EtiquetaSelec extends _$EtiquetaSelec {

  @override
  Set<Etiqueta> build() {
    ref.onAddListener(() {
      print( EtiquetaSelecProvider: onAddListener );
    });
    return {};
  }

  void addEtiquetaSelec(Etiqueta etiqueta) {
    print( se ejecuta el método addEtiquetaSelec );

    print( el state 0 del provider de etiquetas seleccionadas es: ${state.toString()} );
    state = { ...state, etiqueta};
    print( el state 1 del provider de etiquetas seleccionadas es: ${state.toString()} );
  }

  void deleteEtiquetaSelec(Etiqueta etiqueta) {
    state.removeWhere((element) => element.nombre == etiqueta.nombre);
    state = {...state};
  }
}

Chip_etiquetas.dart Widget (UI)

import  package:aap_pos_minegocio/core/app_exports.dart ;
import  package:aap_pos_minegocio/core/common/providers/providers/etiqueta_selec.dart ;
import  package:flutter/material.dart ;
import  package:flutter_riverpod/flutter_riverpod.dart ;

import  ../../../models/etiquetas_model.dart ;

class ChipEtiqueta extends ConsumerStatefulWidget {
  final Etiqueta etiqueta;
  final bool isFilter;
  final VoidCallback? funct;

  const ChipEtiqueta({
    required this.etiqueta,
    this.isFilter = false,
    this.funct,
    super.key,
  });

  @override
  ConsumerState<ChipEtiqueta> createState() => _ChipEtiquetaState();
}

class _ChipEtiquetaState extends ConsumerState<ChipEtiqueta> {
  Set<Etiqueta> filters = <Etiqueta>{};


  @override
  Widget build(BuildContext context) {
    print( se reconstrye el el widget );
    print( el set filters es:$filters );
    final selecEtiquetasProv = ref.read(etiquetaSelecProvider.notifier);
    //filters.contains(widget.etiqueta) == true ? selecEtiquetasProv.addEtiquetaSelec(widget.etiqueta) : null;
    return widget.isFilter
        ? FilterChip(
            label: Text(
              widget.etiqueta.nombre,
              style: Theme.of(context)
                  .textTheme
                  .labelSmall!
                  .copyWith(fontSize: 10.fSize, fontWeight: FontWeight.w600),
            ),
            selected: filters.contains(widget.etiqueta),
            onSelected: (bool selected) {
              print( el bool es: $selected );

              if (selected) {
                selecEtiquetasProv.addEtiquetaSelec(widget.etiqueta);
                setState(() {
                  filters.add(widget.etiqueta);
                });
                //print( eo );
                print( el set filters en callback es:$filters );
                print( bool: ${filters.contains(widget.etiqueta)} );
              } else {
                /*setState(() {
                  filters.remove(widget.etiqueta);
                });*/
                selecEtiquetasProv.deleteEtiquetaSelec(widget.etiqueta);
              }
            },
            shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(50))),
            padding: const EdgeInsets.symmetric(vertical: -7, horizontal: 0),
            labelPadding:
                const EdgeInsets.symmetric(horizontal: 5, vertical: -3),
          )
        : Chip(
            label: Text(
              widget.etiqueta.nombre,
              style: Theme.of(context)
                  .textTheme
                  .labelSmall!
                  .copyWith(fontSize: 10.fSize, fontWeight: FontWeight.w600),
            ),
            shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(50))),
            padding: const EdgeInsets.symmetric(vertical: -7, horizontal: 0),
            labelPadding:
                const EdgeInsets.symmetric(horizontal: 5, vertical: -3),
          );
  }
}

我与** 过滤的Records ** 提供商有奇怪的行为。 在改变被倾听的提供者“古斯塔塞莱克普罗维登”的状态时,人们呼吁退席,因此,在目前这一特定时刻,供应商似乎已经被毁。

我认为,这正导致在要求统一分类表中的记号时,命令清单不会被自动过滤。 谁能帮助我,我会试图过滤命令清单,但在某种程度上,河水供应者没有工作,请!

问题回答

在这方面:

final List<Records> updatedList = recordsList.where((element) => !selectedEtiquetas.contains(element)).toList();

问题是,如果是<条码>所选的Etiquetas,即<条码>;Etiqueta>,即<条码>,即<条码>。 Unless Records is supplemented from Etiqueta , thiseck will nor Returncode>true.


About ref.onDispose:

它用于登记火焰在internal State重建的警报。 因此,预计行为会发生。 见。 旧处置法





相关问题
Flutter App cannot be installed on Android TV

I m building a Flutter app that should support Android TV and Mobile devices. Despite Google Play shows that it is supported, I cannot install app on my MiBox device. While trying to install it, both ...

Moving the icon button to the right causes rendering issues

I am trying to align the icon button to the right of the Text field, I tried the row which made the icon button not centered vertically and now I am trying out the Stack widget. Here is my code - ...