Flutter-列上的setState不起作用

时间:2018-07-19 12:10:15

标签: dart widget flutter setstate

我会尝试解释,

我有一个方法名称为createList的人:(此方法只是创建列表并返回包含此列表的列)

Widget criarLista(int qtd){
    if(widget.listas.length == 1){
      return  new Text(
      widget.listas[0].Descricao,
          textAlign: TextAlign.center,
          style: new TextStyle(color: Colors.red));

    }else {
      for (int i = widget.listas.length; i >= 1; i--) {
        for (int j = 1; j < i; j++) {
          if (widget.listas[j - 1].TotalVendas < widget.listas[j].TotalVendas) {
            var aux1 = widget.listas[j].TotalVendas;
            widget.listas[j].TotalVendas = widget.listas[j - 1].TotalVendas;
            widget.listas[j - 1].TotalVendas = aux1;

            var aux2 = widget.listas[j].CodigoProduto;
            widget.listas[j].CodigoProduto = widget.listas[j - 1].CodigoProduto;
            widget.listas[j - 1].CodigoProduto = aux2;


            var aux3 = widget.listas[j].Descricao;
            widget.listas[j].Descricao = widget.listas[j - 1].Descricao;
            widget.listas[j - 1].Descricao = aux3;


            var aux4 = widget.listas[j].QtdVendida;
            widget.listas[j].QtdVendida = widget.listas[j - 1].QtdVendida;
            widget.listas[j - 1].QtdVendida = aux4;
          }
        }
      }
      List<Widget> listaTiles = new List();
      for(int i = 0; i <= qtd; i++){
        listaTiles.add(
            new Padding(
              padding: new EdgeInsets.only(left: 20.0, right: 20.0, bottom: 7.0),
              child:
              new Container(
                child:
                new ListTile(
                  title: new Text(widget.listas[i].Descricao.toString(), style: new TextStyle(color: Colors.white, fontSize: 17.0, fontWeight: FontWeight.bold)),
                  subtitle: new Text(
                      "NºVendas : " + widget.listas[i].QtdVendida.toString() + "\n" +
                          "Vendas: " +
                          formatador(widget.listas[i].TotalVendas).toString(), style: new TextStyle(color: Colors.white)),
                  trailing: new Icon(escolherIcone(i), color: Colors.white,),
                ),
                decoration: new BoxDecoration (
                  borderRadius: new BorderRadius.all(new Radius.circular(10.0)),
                  color: Colors.lightBlue,
                ),
                padding: new EdgeInsets.fromLTRB(16.0, 5.0, 16.0, 5.0),
              ),));

      }



      Widget test = new Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            listaTiles[0],
            listaTiles[1],
            listaTiles[2]

          ]
      );

      return test;

    }

  }

我想在第一个条件中输入

if(widget.listas.length == 1){
      return  new Text(
      widget.listas[0].Descricao,
          textAlign: TextAlign.center,
          style: new TextStyle(color: Colors.red));

    }

使用setState起作用的按钮,但是我真正的构建类在哪里

class RelatorioDasVendasTotsProdutos extends StatefulWidget {
  @override
  RelatorioDasVendasTotsProdutosState createState() => RelatorioDasVendasTotsProdutosState();
}

class RelatorioDasVendasTotsProdutosState extends State<RelatorioDasVendasTotsProdutos> {



  @override
  Widget build(BuildContext context) {


    double height =  (MediaQuery.of(context).size.height) - kRadialReactionRadius - kToolbarHeight;
    return new Container(
      height: height,
      padding: new EdgeInsets.all(10.0),
      child: new Card(
        elevation: 10.0,
        child:
        new Column(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              new Column(crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  new ListTile(
                    title: new Center(child: new Text('VENDAS POR PRODUTOS', style: new TextStyle(fontWeight: FontWeight.bold))),
                    subtitle: new Center(child: new Padding(padding: new EdgeInsets.only(top: 5.0), child:
                    new Text('Top 3 produtos dos ultimos 30 dias', textAlign: TextAlign.center,))),

                  ),

                  new FutureBuilder<List<RelatorioProdutos>>(
                    future: fetchRelatorioPorProduto(new http.Client(),'$dateInicial', '$dateFinal'),
                    builder: (context, snapshot) {
                      if (snapshot.hasError) print(snapshot.error)
                      ;else
                        auxTelaDetalhada = RelatorioVendasTotalizadasProdutos(prods: snapshot.data, aondeVoltar: 0,);


                      return snapshot.hasData

                          ? new porProdutoList(listas: snapshot.data)
                          : new Center(child: new RefreshProgressIndicator());

                    },
                  ),
                ],),

              new Column(crossAxisAlignment: CrossAxisAlignment.end,
                  children: <Widget>[
                    new Padding(padding: new EdgeInsets.only(bottom: 15.0),
                      child: new RaisedButton(
                        child: new Text("Ver Relatório Completo",
                          style: new TextStyle(color: Colors.white, fontSize: 20.0),),
                        color: Colors.blue,
                        elevation: 8.0,
                        splashColor: Colors.lightBlue,
                        onPressed: () {
                          setState(() {
                          });
//                          Navigator.pushReplacement(
//                            context,
//                            new MaterialPageRoute(builder: (context) => auxTelaDetalhada),
//                          );
                        },
                      ),
                    ),

                  ]),]

        ),




      ),

    );

  }

}

在另一个地方,当按下最后一个按钮时,它可以工作,但是我想在第一个if(在其他类中)输入时重新构建它。

0 个答案:

没有答案