0

I will try explain,

I have and method name createList who make it: (this method just create the list and return a column with this list)

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;

    }

  }

i want to when enter in the first if

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

    }

appers a button that setState works, but my real build class is where

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),
//                          );
                        },
                      ),
                    ),

                  ]),]

        ),




      ),

    );

  }

}

In another place, when this last button is pressed, it works, but i want to if enter in the first if(in other class) rebuild it.

6
  • new Column(...) within setState(() { ... }) looks very weird, you probably don't want to do that. setState() should only be used to update state. This causes build() to be executed again and in build() you instantiate the widgets depending on the state. Jul 19, 2018 at 12:13
  • onPressed: () { setState(() { build(context); }); }, Jul 19, 2018 at 12:15
  • like this? the button still doing nothing. Jul 19, 2018 at 12:16
  • No, don't call build yourself, Flutter calls build for you when you call setState(). In setState() only modify the state (values of fields of the widget). Jul 19, 2018 at 12:17
  • Wow, i did just setState() on other button and it worked, i get the realoded screen, but i can make if an error ocurred appers a button with this setState property? Because it worked on other button on real method Jul 19, 2018 at 12:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.