This is my code where I am showing list of pending invoices.But when i accept the it should reload the pending invoice widget after clicking on snack bar action button.When user clicks on accept button its showing snack bar and when pressed accept action button snack bar it navigate back to same widget where I needs to update that widget along with new list of pending invoices without the invoice which we have accepted
I wants to reload and update the widget in flutter when clicked on action button of snack bar
You can use the
setStatemethod to update the state of your widget and trigger a rebuild of the widget with the updated list of pending invoices. In the callback function for the snack bar’s “accept” action button, you can call
setStateto update the list of pending invoices and remove the invoice that was accepted. You can pass a function to
setStatethat takes the previous state as an argument and returns the updated state, like so:
pendingInvoices: prevState.pendingInvoices.where((invoice) => invoice.id != acceptedInvoiceId).toList()
This code will remove the invoice from the list using
You can also use the
updatemethod of the
Futureclass in the callback function for the snack bar’s “accept” action button. This will update the list of pending invoices and remove the invoice that was accepted.
pendingInvoices = pendingInvoices.where((invoice) => invoice.id != acceptedInvoiceId).toList();
This will wait for 2 seconds before updating the state and removing the invoice from the list. Please make sure you are passing correct invoice id.