getx icon indicating copy to clipboard operation
getx copied to clipboard

Get.back() not work after Get.snackbar

Open dengwei555 opened this issue 1 year ago • 5 comments

Describe the bug Use Get.snackbar() first in a component, and then continue to use Get.back(), neither of which takes effect

**Reproduction code

example:

class ServiceView extends GetView<ServiceController> {
  const ServiceView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('ServiceView'),
        centerTitle: true,
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            Get.snackbar("notice", "noticeContent");

            Get.back();
          },
          child: const Text(
            "notice and back",
          ),
        ),
      ),
    );
  }
}

To Reproduce Steps to reproduce the behavior:

  1. use get create page service create page
  2. Add example code to the view page

Expected behavior Prompt information and return to the previous page

Screenshots image

Flutter Version: 3.10.5

Getx Version: 4.6.5

Describe on which device you found the bug: ex: Chrome,android emulator, android device

Minimal reproduce code

ElevatedButton(
          onPressed: () {
            Get.snackbar("notice", "noticeContent");

            Get.back();
          },
          child: const Text(
            "notice and back",
          ),
        ),

dengwei555 avatar Jun 30 '23 03:06 dengwei555

@dengwei555

  • Get.back() in this case mean you close "SnackBar"
  • Try to move Get.back() before show SnackBar like this
ElevatedButton(
          onPressed: () {
            Get.back();
            Get.snackbar("notice", "noticeContent");
          },
          child: const Text(
            "notice and back",
          ),
        ),

quocbao238 avatar Jun 30 '23 09:06 quocbao238

On an Apple phone, when the snackbar pops up, immediately sliding back to the previous page can also cause problems. So what should we do?

iOS-Kel avatar Aug 02 '23 01:08 iOS-Kel

Agree with the last comment

haroke4 avatar Jan 23 '24 17:01 haroke4

As a workaround, we can use Get.until((route) => route== 'Name of your route');

nasserallah-hourichi avatar Feb 23 '24 14:02 nasserallah-hourichi

Approach 1: if you want to display snackbar and then want to navgate back to screen, you can this properties: snackbarStatus

Get.snackbar(
      'Title',
      'Message',
      snackbarStatus: (status) {
        if (status == SnackbarStatus.CLOSED) {
          // ..
        }
      },
    );

Approach 2: Closing a snackbar dynamically is a handy feature for when you need to return to a screen with open dialogues, bottom sheets, or snackbars. checkout this Reference

Get.back(closeOverlay = true / false) exists for this.

Zaveri21 avatar May 20 '24 15:05 Zaveri21