FutureBuilder: future function calling even after push navigator












1















I have a listview that returns a list of orders from my local database(sqflite) and it's working very well.



After a tile of the list is tapped I push the navigation to another page, when my second page is loaded I notice that future function is called again, my second page loads and works normally but to me it seems unnecessary to call the future function again.



Can I control this behavior?



Here is my code for the first page:



import 'package:flutter/material.dart';
import '../model/coleta.dart';
import 'coletarPedido.dart';

void selectedOrderTile(PedidoColeta pedidoColeta, BuildContext context) {
Navigator.push(context, new MaterialPageRoute(builder: (context) => new ColetaPage(pedidoColeta: pedidoColeta)));
}

Future<List<PedidoColeta>> listaPedidosAguardandoColeta() async {
return await PedidoColeta.retornaListaPedidosColeta(1);
}

Widget pedidosAguardandoColeta(context) {
return new FutureBuilder<List<PedidoColeta>> (
future: listaPedidosAguardandoColeta(),
builder: (BuildContext context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.data == null || snapshot.data.length == 0) {
return new Text("Nenhum pedido por aqui!");
} else {
return new ListView.separated(
padding: const EdgeInsets.all(8.0),
itemCount: snapshot.data.length,
itemBuilder: (context, i) {
return tilePedido(snapshot.data[i], context);
},
separatorBuilder: (context, i) {
return Divider();
},
);
}
}
return new Container(
alignment: AlignmentDirectional.center,
child: new CircularProgressIndicator()
);
},
);
}

Widget tilePedido(PedidoColeta pedidoColeta, context) {
return ListTile(
leading: new Container(
width: 50.0,
height: 50.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey[300],
image: new DecorationImage(
fit: BoxFit.fill,
image: AssetImage(pedidoColeta.logoCliente)
)
)
),
title: Text('Pedido: ' + pedidoColeta.idPedido.toString() + ' Ocam: ' + pedidoColeta.idOcam.toString(), style: Theme.of(context).textTheme.button),
subtitle: Text('Total de Itens: ' + pedidoColeta.qtdItem.toString() + 'nData de Saída: ' + pedidoColeta.dataSaida.toString()),
dense: true,
onTap: () => selectedOrderTile(pedidoColeta, context),
);
}









share|improve this question





























    1















    I have a listview that returns a list of orders from my local database(sqflite) and it's working very well.



    After a tile of the list is tapped I push the navigation to another page, when my second page is loaded I notice that future function is called again, my second page loads and works normally but to me it seems unnecessary to call the future function again.



    Can I control this behavior?



    Here is my code for the first page:



    import 'package:flutter/material.dart';
    import '../model/coleta.dart';
    import 'coletarPedido.dart';

    void selectedOrderTile(PedidoColeta pedidoColeta, BuildContext context) {
    Navigator.push(context, new MaterialPageRoute(builder: (context) => new ColetaPage(pedidoColeta: pedidoColeta)));
    }

    Future<List<PedidoColeta>> listaPedidosAguardandoColeta() async {
    return await PedidoColeta.retornaListaPedidosColeta(1);
    }

    Widget pedidosAguardandoColeta(context) {
    return new FutureBuilder<List<PedidoColeta>> (
    future: listaPedidosAguardandoColeta(),
    builder: (BuildContext context, snapshot) {
    if (snapshot.connectionState == ConnectionState.done) {
    if (snapshot.data == null || snapshot.data.length == 0) {
    return new Text("Nenhum pedido por aqui!");
    } else {
    return new ListView.separated(
    padding: const EdgeInsets.all(8.0),
    itemCount: snapshot.data.length,
    itemBuilder: (context, i) {
    return tilePedido(snapshot.data[i], context);
    },
    separatorBuilder: (context, i) {
    return Divider();
    },
    );
    }
    }
    return new Container(
    alignment: AlignmentDirectional.center,
    child: new CircularProgressIndicator()
    );
    },
    );
    }

    Widget tilePedido(PedidoColeta pedidoColeta, context) {
    return ListTile(
    leading: new Container(
    width: 50.0,
    height: 50.0,
    decoration: new BoxDecoration(
    shape: BoxShape.circle,
    color: Colors.grey[300],
    image: new DecorationImage(
    fit: BoxFit.fill,
    image: AssetImage(pedidoColeta.logoCliente)
    )
    )
    ),
    title: Text('Pedido: ' + pedidoColeta.idPedido.toString() + ' Ocam: ' + pedidoColeta.idOcam.toString(), style: Theme.of(context).textTheme.button),
    subtitle: Text('Total de Itens: ' + pedidoColeta.qtdItem.toString() + 'nData de Saída: ' + pedidoColeta.dataSaida.toString()),
    dense: true,
    onTap: () => selectedOrderTile(pedidoColeta, context),
    );
    }









    share|improve this question



























      1












      1








      1








      I have a listview that returns a list of orders from my local database(sqflite) and it's working very well.



      After a tile of the list is tapped I push the navigation to another page, when my second page is loaded I notice that future function is called again, my second page loads and works normally but to me it seems unnecessary to call the future function again.



      Can I control this behavior?



      Here is my code for the first page:



      import 'package:flutter/material.dart';
      import '../model/coleta.dart';
      import 'coletarPedido.dart';

      void selectedOrderTile(PedidoColeta pedidoColeta, BuildContext context) {
      Navigator.push(context, new MaterialPageRoute(builder: (context) => new ColetaPage(pedidoColeta: pedidoColeta)));
      }

      Future<List<PedidoColeta>> listaPedidosAguardandoColeta() async {
      return await PedidoColeta.retornaListaPedidosColeta(1);
      }

      Widget pedidosAguardandoColeta(context) {
      return new FutureBuilder<List<PedidoColeta>> (
      future: listaPedidosAguardandoColeta(),
      builder: (BuildContext context, snapshot) {
      if (snapshot.connectionState == ConnectionState.done) {
      if (snapshot.data == null || snapshot.data.length == 0) {
      return new Text("Nenhum pedido por aqui!");
      } else {
      return new ListView.separated(
      padding: const EdgeInsets.all(8.0),
      itemCount: snapshot.data.length,
      itemBuilder: (context, i) {
      return tilePedido(snapshot.data[i], context);
      },
      separatorBuilder: (context, i) {
      return Divider();
      },
      );
      }
      }
      return new Container(
      alignment: AlignmentDirectional.center,
      child: new CircularProgressIndicator()
      );
      },
      );
      }

      Widget tilePedido(PedidoColeta pedidoColeta, context) {
      return ListTile(
      leading: new Container(
      width: 50.0,
      height: 50.0,
      decoration: new BoxDecoration(
      shape: BoxShape.circle,
      color: Colors.grey[300],
      image: new DecorationImage(
      fit: BoxFit.fill,
      image: AssetImage(pedidoColeta.logoCliente)
      )
      )
      ),
      title: Text('Pedido: ' + pedidoColeta.idPedido.toString() + ' Ocam: ' + pedidoColeta.idOcam.toString(), style: Theme.of(context).textTheme.button),
      subtitle: Text('Total de Itens: ' + pedidoColeta.qtdItem.toString() + 'nData de Saída: ' + pedidoColeta.dataSaida.toString()),
      dense: true,
      onTap: () => selectedOrderTile(pedidoColeta, context),
      );
      }









      share|improve this question
















      I have a listview that returns a list of orders from my local database(sqflite) and it's working very well.



      After a tile of the list is tapped I push the navigation to another page, when my second page is loaded I notice that future function is called again, my second page loads and works normally but to me it seems unnecessary to call the future function again.



      Can I control this behavior?



      Here is my code for the first page:



      import 'package:flutter/material.dart';
      import '../model/coleta.dart';
      import 'coletarPedido.dart';

      void selectedOrderTile(PedidoColeta pedidoColeta, BuildContext context) {
      Navigator.push(context, new MaterialPageRoute(builder: (context) => new ColetaPage(pedidoColeta: pedidoColeta)));
      }

      Future<List<PedidoColeta>> listaPedidosAguardandoColeta() async {
      return await PedidoColeta.retornaListaPedidosColeta(1);
      }

      Widget pedidosAguardandoColeta(context) {
      return new FutureBuilder<List<PedidoColeta>> (
      future: listaPedidosAguardandoColeta(),
      builder: (BuildContext context, snapshot) {
      if (snapshot.connectionState == ConnectionState.done) {
      if (snapshot.data == null || snapshot.data.length == 0) {
      return new Text("Nenhum pedido por aqui!");
      } else {
      return new ListView.separated(
      padding: const EdgeInsets.all(8.0),
      itemCount: snapshot.data.length,
      itemBuilder: (context, i) {
      return tilePedido(snapshot.data[i], context);
      },
      separatorBuilder: (context, i) {
      return Divider();
      },
      );
      }
      }
      return new Container(
      alignment: AlignmentDirectional.center,
      child: new CircularProgressIndicator()
      );
      },
      );
      }

      Widget tilePedido(PedidoColeta pedidoColeta, context) {
      return ListTile(
      leading: new Container(
      width: 50.0,
      height: 50.0,
      decoration: new BoxDecoration(
      shape: BoxShape.circle,
      color: Colors.grey[300],
      image: new DecorationImage(
      fit: BoxFit.fill,
      image: AssetImage(pedidoColeta.logoCliente)
      )
      )
      ),
      title: Text('Pedido: ' + pedidoColeta.idPedido.toString() + ' Ocam: ' + pedidoColeta.idOcam.toString(), style: Theme.of(context).textTheme.button),
      subtitle: Text('Total de Itens: ' + pedidoColeta.qtdItem.toString() + 'nData de Saída: ' + pedidoColeta.dataSaida.toString()),
      dense: true,
      onTap: () => selectedOrderTile(pedidoColeta, context),
      );
      }






      flutter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 16:02









      MTCoster

      3,83422141




      3,83422141










      asked Nov 22 '18 at 15:44









      limarslimars

      212




      212
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434385%2ffuturebuilder-future-function-calling-even-after-push-navigator%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434385%2ffuturebuilder-future-function-calling-even-after-push-navigator%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]