-2
I’m having trouble updating the status I’m taking a list and showing her If I put Setstate in _getProdPro loops, if I don’t put, the data is not updated on the screen, someone knows how I can call correctly
import 'package:gestoque/ConsultaPromocao.dart';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'package:gestoque/Api.dart';
class ViewProdutosPromocionais extends StatefulWidget {
@override
_ViewProdutosPromocionaisState createState() =>
_ViewProdutosPromocionaisState();
}
class _ViewProdutosPromocionaisState extends State<ViewProdutosPromocionais> {
var promocoes = new List<ConsultaPromocao>();
String _search;
Future<List> _getPromocoes() async {
Api.getProdPromo().then((response) {
List lista = json.decode(response.body);
promocoes =
lista.map((model) => ConsultaPromocao.fromJson(model)).toList();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Image.asset("assets/logo_topo_1.png"),
backgroundColor: Colors.orange,
),
backgroundColor: Colors.white,
body: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(10.0),
child: TextField(
decoration: InputDecoration(
labelText: "Nome do Produto",
labelStyle: TextStyle(color: Colors.black),
border: OutlineInputBorder()),
style: TextStyle(color: Colors.black, fontSize: 18.0),
textAlign: TextAlign.center,
),
),
Expanded(
child: FutureBuilder(
future: _getPromocoes(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
case ConnectionState.none:
return Container(
width: 200.0,
height: 200.0,
alignment: Alignment.center,
child: CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation<Color>(Colors.orange),
strokeWidth: 5,
),
);
default:
if (snapshot.hasError)
return Container();
else
return ListaProdutosPromocionais();
}
},
),
)
],
));
}
ListaProdutosPromocionais() {
return ListView.builder(
itemCount: promocoes.length,
itemBuilder: (context, index) {
return Container(
child: Card(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Text('Código: : ',
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.bold)),
Text(promocoes[index].codprod),
],
),
Row(
children: <Widget>[
Text('Nome: ',
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.bold)),
Text(promocoes[index].descrprod),
],
),
Row(
children: <Widget>[
Text('Valor R\$ ',
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.bold)),
Text(promocoes[index].vlrvenda),
],
),
],
),
));
});
}
}
Take the bold from your question
– GabrielLocalhost