【问题标题】:FutureBuilder with Provider: List is not a subtype of type Future<List>FutureBuilder with Provider: List 不是 Future<List> 类型的子类型
【发布时间】:2020-09-18 06:52:39
【问题描述】:

我需要以动态方式创建一个元素列表,并且用户可以自然地修改它们,这个想法是在将数据插入到显示我那个或那些元素的排列中之后

  FutureBuilder<List<Detalleconcepto>>(
                    future:  provider.listado,
                    builder: (BuildContext context,
                        AsyncSnapshot<List<Detalleconcepto>> snapshot) {
                      if (snapshot.hasData) {
                        return _listConceptos(snapshot.data);
                      } else {
                        return Center(
                          child: contenedor(),
                        );
                      }
                    },
                  ),

我将留下我的提供者模型和列表的参考

class ProviderInfo with ChangeNotifier {
  List<Detalleconcepto> _listado = new List<Detalleconcepto>();

  get listado {
    return _listado;
  }

  set listado(List<Detalleconcepto> listado) {
    this._listado = listado;
    notifyListeners();
  }
}
class Detalleconcepto {
  int idOperacionFinanciera;
  int idTipoConcepto;
  String tipoConcepto;
  double importe;
  String fecha;
  String numeroDocumento;

  Detalleconcepto({
    this.idOperacionFinanciera,
    this.idTipoConcepto,
    this.tipoConcepto,
    this.importe,
    this.fecha,
    this.numeroDocumento,
  });

════════小部件库捕获的异常═════════════════════════════════════ ═ “List”类型不是“Future>”类型的子类型

相关的导致错误的小部件是 创建列表

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    只有当您有在 Future 中返回的数据时,您才需要 FutureBuilder,即异步
    由于在您的情况下同步返回数据,您不需要FutureBuilder

    _listConceptos(provider.listado), // instead of FutureBuilder
    

    【讨论】:

      猜你喜欢
      • 2020-09-20
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 2020-09-08
      • 1970-01-01
      相关资源
      最近更新 更多