How to create a snackbar/toast alert when connected and disconnected and have the message show the type of connection?

Viewed 36

I have a task that I have to create, like a snack bar message in Flutter. If the device is connected, the Snackbar or Toast package will show the message + green background, and when disconnected, it will show the message + red background color. The message will show by what we are connected (by cellular, wifi, or etc.).

1 Answers

Start by adding the connectivity_plus package, it includes a simple listener which you can implement in your app to be notified if the connectivity changed enter code here(disconnected, wifi, cellular..)

https://pub.dev/packages/connectivity_plus

onConnectivityChanged.listen will return a ConnectivityResult which you can use to show different types of snackbars, here is an example :

https://pub.dev/packages/top_snackbar_flutter

Hope it works for you, good luck.

Related