FutureBuilder: future function calling even after push navigator
up vote
1
down vote
favorite
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
add a comment |
up vote
1
down vote
favorite
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
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
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
flutter
edited Nov 22 at 16:02
MTCoster
2,68521838
2,68521838
asked Nov 22 at 15:44
limars
212
212
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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