jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.1k stars 1.58k forks source link

Get.back() not work after Get.snackbar #2831

Open dengwei555 opened 1 year ago

dengwei555 commented 1 year ago

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",
          ),
        ),
quocbao238 commented 1 year ago

@dengwei555

iOS-Kel commented 12 months ago

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?

haroke4 commented 6 months ago

Agree with the last comment

Nasserallah-hour commented 5 months ago

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

Zaveri21 commented 2 months ago

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.