I want to reload my list when Navigator.pop, but i can't do that.
My code:
class ConfigCNPJPage extends StatefulWidget {
bool voltarTela;
ConfigCNPJPage({Key key, this.voltarTela}) : super(key: key);
@override
ConfigCNPJPageState createState() => new ConfigCNPJPageState();
}
class ConfigCNPJPageState extends State<ConfigCNPJPage>
with SingleTickerProviderStateMixin {
ResultConfig BD;
List<Map> list;
List<Widget> listArray = [];
Stream myStream;
Future setupList() async {
ConfigDatabase db = ConfigDatabase();
var banco = await db.initDB();
list = await banco.rawQuery('SELECT * FROM Empresa');
return list;
}
@override
void initState() {
super.initState();
myStream = setupList()?.asStream();
}
@override
Widget build(BuildContext context) {
return new StreamBuilder(
stream: myStream,
builder: (BuildContext context, AsyncSnapshot snapshot) {
return snapshot.hasData? new Scaffold(
resizeToAvoidBottomPadding: false,
appBar: new AppBar(
title: new Text('Configurar Empresa'),
actions: <Widget>[
new IconButton(icon: const Icon(Icons.add), onPressed: () {
Navigator.pushNamed(context, "NovoCNPJ").then((value) {
setState(() {
myStream = setupList()?.asStream();
});
});
})
],
),
body: new Column(
children: <Widget>[
criarLista()
],
),
):new Center(child: new RefreshProgressIndicator());
},);
}
}
I want to reaload this Stream after the pop, with the setState, but isn't working. Anyone can help?
I needs to rebuild that StreamBuilder? or reload just the list?
With the StreamBuilder, i need to do the setState and if i got the streamBuilder rebuilded it will work?