I've got a small Flutter application with a structure like this:
HomePage
PageView
Tab1 - list of data w/ FutureBuilder
Tab2 - list of data w/ StreamBuilder
Tab3 - list of data w/ StreamBuilder
Floating Action Button
The FAB does a different thing based on which tab is currently active (i.e. on Tab1 it opens an "Add New Thing" form, but on Tab2 it opens an "Add New Category of Thing" form). When I tap the FAB from Tab1 and then complete & submit the "Add New Thing" form, I am returned to the Tab1 view - but the data isn't being refreshed. (The future is defined in a variable outside the build method specifically so it isn't called every time the view is loaded - but I need to be able to load it on-demand occasionally.)
The FAB/submit/return to view process works as expected on Tab2 and Tab3, I suspect because they are streams - but I can't use a stream on Tab1. So how can I force Tab1 to refresh the future it's using when I submit the form & pop the view?
Here's the FAB code & the form code snippets...
/// FloatingActionButton code snippet
onPressed: () async {
switch (selectedPage) {
case 0:
debugPrint('add a new transaction');
await Navigator.of(context).push(MaterialPageRoute(
fullscreenDialog: true,
builder: (context) => AddTransactionTest()));
setState(() {});
... other cases for Tab2, Tab3 etc
/// Form code snippet
onPressed: () async {
try {
// do some stuff
await insertTransaction(txn);
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Transaction saved!')));
Navigator.pop(context);
}
... error-handling stuff