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: prabin maharjan

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


Solution 2: Jahidul Islam

To return data to the first screen, use the Navigator.pop() method and then show snackbar

  ElevatedButton(
            onPressed: () {
              // Close the screen and return "test!" as the result.
              Navigator.of(context).pop();
              ScaffoldMessenger.of(context)
                ..removeCurrentSnackBar()
                ..showSnackBar(const SnackBar(content: Text('test')));
            },
            child: const Text('close!'),
          )

For more read this article


Solution 3: MOHAMMED MISHAL N.M

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