'ScaffoldMessenger showSnackBar on Navigator.push or .pop?

As simple as it sounds, what's the current method to display a snackbar through the ScaffoldMessenger after a Navigator.pop into the previous page, where the snackbar is shown on the now current page (previous)?



Solution 1:[1]

first show the snackbar using ScaffoldMessenger.of(context) ..hideCurrentSnackBar() ..showSnackBar(SnackBar(content: Text(message))); and later you can use Navigator.pop();

Solution 2:[2]

content: Text(response['message']), backgroundColor: primaryColor, dismissDirection: DismissDirection.up, ); ScaffoldMessenger.of(context).showSnackBar(snackBar); Navigator.of(context).pop()

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 prabin maharjan
Solution 2