Skip to content

Handling Multiple snack bars Display Issues in Concurrent API Calls. #3151

Closed Answered by dharambudh1
khushpajwani asked this question in Q&A
Discussion options

You must be logged in to vote

Try using this code:

  void showSnackbar({required String title, required String message}) {
    unawaited(
      Get.closeCurrentSnackbar().whenComplete(
        () {
          Get.snackbar(title, message, instantInit: false);
          return;
        },
      ),
    );
    return;
  }

Explanation:
The showSnackbar function first attempts to close any currently displayed snack bar using Get.closeCurrentSnackbar(). Once the current snack bar is closed (as ensured by the whenComplete callback), it then displays a new snack bar with the provided title and message. The use of unawaited suggests that the function is designed to run independently of the completion of the Future from Get.clos…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by khushpajwani
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants