jonataslaw / getx

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

How prevent Get.snackbar from closing if i use Navigator.of(context).pop()? #1120

Open astrO1 opened 3 years ago

astrO1 commented 3 years ago

I have a Custom Dialog Progress but when something goes wrong i show the Get.snackbar this on my code:

  return InkWell(
    onTap: () async {                        
      Navigator.of(widget.scaffoldKey.currentContext).pop();
      UtilService.showLoading(widget.scaffoldKey.currentContext, 'Selecionando endereço');
      Timer(Duration(seconds: 1), () {
          //
          _con.changeDeliveryAddress(_con.addresses.elementAt(index))
          .then((value) async {
              Navigator.of(widget.scaffoldKey.currentContext).pop();
          });
      });
    },

This line of code Navigator.of(widget.scaffoldKey.currentContext).pop(); is simple to remove the dialog that i created but if somethings wrong inside this function i show a Get.snackbar

  Future<void> changeDeliveryAddress(model.Address address) async {
    MapsUtil mapsUtil = new MapsUtil();
    return await mapsUtil.getTaxByDistance(address, restaurantService.getRestaurant().id)
    .then((value) async {
      if(value['success']) {
        await settingRepo.changeCurrentLocation(address);
        setState(() {
          settingRepo.deliveryAddress.value = address;
        });
        settingRepo.deliveryAddress.notifyListeners();
      } else {
        UtilService.showErrorSnack('Este restaurante não atende esta região');
      }
      return value;
    });
  }
  static showErrorSnack(message) {
    Get.snackbar("Atenção", message, backgroundColor: ThemeColor.AppErroColor, colorText: Colors.white);
  }

The problem is that this code removes the snackbar, not the Dialog is like this snackbar is a dialog

FabioPagano commented 3 years ago

Maybe Snackbar managed by ScaffoldMessenger (new in Flutter 2.0) can be of help.