I'm working on some sort of time tracking application. The main idea behind it is simple - add the number of hours for a wanted project and display the sum of hours per day.
I'm using Flutter and dart for this and I have the following: - List of cards for every weekday - Cards have Gesture detector tap implemented - this action will show all projects for the selected day - AlertDialog pop-up to add the hours
I'm trying to refresh the total number of hours for the selected day on Alert Dialog pop-up close without reloading all the data.
Can someone help me with any idea how to implement the refresh?
What I've tried so far is the following:
Desired behavior for this will be to click on the card and display all the projects for the selected day. After adding a new value I want to return to the same place (with opened card) and the newly added project will show up on the list along with updated total hours for the day.
For now, I got edit partially done. I open the card and edit one of the existing project. The data is saved, but when I return to the previous screen I cannot update the hours on the UI. When I open the edit screen once more the shown data is as expected.
First you need to call your showDialog
within a Stateful Widget
in order to have access, has the name suggests, to a state. Then, within that screen, you can call a method and display your dialog and it will return a Future<void>
which means you can perform so action after the dialog is dismissed, such as
showDialog(// Yours params).then((_)=>setState((){}));
and your UI will be updated to match changes.
Return true in pop Navigator from the dialog when want to refresh the screen
FlatButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: Text("Close"))
Refresh screen when getting true in result
final result = await showDialog<bool>(
context: context,
builder: (context) => MyDialog(),
)
if(result){// refresh screen}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With