'Show Snackbar Reactively Using GetX in Flutter

This is the scenario

  1. Making an API call
  2. Response is empty
  3. Need to show 'No results found' msg to the user through Snackbar from GetX controller
  4. But I don't want to pass the instance of the view class to the controller to show the Snackbar.
  5. Is there any Getx widget that listens to the msg.obs value in the controller and executes Get.Snackbar() code in the view


Solution 1:[1]

You can use below code for show snackbar in flutter

 Get.snackbar(
    "Hello",
    "Thank You!",
    snackPosition: SnackPosition.TOP,
    colorText: Colors.white,
    borderRadius: 10,
    backgroundColor:  AppColors.toastGreenColor ,
    icon: Image.asset(
      "assets/images/success_toast.png",
      height: 25,
      width: 25,
      color: Colors.white,
    ),
  );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ravi Limbani