Refresh ListView in Flutter

1,121 views
Skip to first unread message

Tony Seng

unread,
Nov 19, 2019, 4:24:27 AM11/19/19
to Flutter Development (flutter-dev)

How can I refresh a ListView ? Let say in page A, I have a ListView, and there is a menu icon in the row item. When I click the menu icon, it will show a bottom sheet dialog which has a delete icon. When delete icon is clicked, it will pop up a delete confirmation dialog. Once the 'Yes' button in confirmation dialog is clicked, it will delete the item. Once it received the "Success" status, it will refresh the ListView. This is the code for bottom sheet delete icon


onTap: () {
          Navigator.pop(context);
          var result =  PopUpDialog().showDeleteDialog();   // pop up confirmation dialog
          if (result == 'Success') {
                print('success');
                setState(() {
                  data.removeAt(index);
               });
           } else {
               print('fjeodpedp');
           }
         },

And this is the code for Yes button in confirmation dialog.

PopUpDialog-showDeleteDialog

  onPressed: () async {
      Navigator.pop(buildContext);   // dismiss confirmation dialog
          var result = await _bloc.delete();
          return result;
    },
Bloc class
Future delete() async {
    Response delete = await _repo.delete();  // delete data in server
    var deleteResponse = Response.fromJson(delete.body);
    return deleteResponse.status;   // return Success
  }


I want the setState get called only if deleteResponse.status is equal to success, but it keep printing fjeodpedp  once the confirmation dialog is pop up. I have added async-await, but still not working.


What is the correct way?


Thanks for your valuable time.

Thomas Verbeek

unread,
Nov 19, 2019, 8:42:19 AM11/19/19
to Flutter Development (flutter-dev)
You did not provide the info from which package Response was included. The standard Dart Response class does not offer a static method „fromJson“.
My guess is, that the deleteResponse.status method does not return the String „Success“, which would be very unusual. It probably returns an Enum.

Best regards,

Tom.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/7d125c89-dbb7-40c6-acb7-6214fc6dced1%40googlegroups.com.

Tony Seng

unread,
Nov 19, 2019, 9:56:33 AM11/19/19
to Flutter Development (flutter-dev)
What I have missed out ???

--
You received this message because you are subscribed to a topic in the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/flutter-dev/OapgKK_dwZA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to flutter-dev...@googlegroups.com.


--
Whatever you are , be a good one.
Reply all
Reply to author
Forward
0 new messages