Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!
We spend hours on Instagram and YouTube and waste money on coffee and fast food, but wonβt spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!
Learn from Guru Rajesh Kumar and double your salary in just one year.

first install this package connectivity
Run this command:
With Flutter:
$ flutter pub add connectivity
Import it
Now in your Dart code, you can use:
import 'package:connectivity/connectivity.dart';
Main.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// before rendering your main page use write a condition | |
var connectivityResult = await (Connectivity().checkConnectivity()); | |
if (connectivityResult == ConnectivityResult.mobile) { | |
// this will show when your device is connected with mobile network | |
print("connected to mobile data"); | |
// ignore: unused_local_variable | |
ScaffoldMessenger.of(context).showSnackBar( | |
SnackBar( | |
content: const Text('Connected to mobile network'), | |
backgroundColor: Colors.green, | |
), | |
); | |
else if(connectivityResult == ConnectivityResult.wifi){ | |
// this will show when your device is connected with wifi | |
print("connected to wifi"); | |
ScaffoldMessenger.of(context).showSnackBar( | |
SnackBar( | |
content: const Text('Connected to wifi network '), | |
backgroundColor: Colors.green, | |
), | |
); | |
}else { | |
// This will shown when your device is disconnected | |
ScaffoldMessenger.of(context).showSnackBar( | |
SnackBar( | |
content: const Text('No internet connection'), | |
backgroundColor: Colors.black, | |
action: SnackBarAction( | |
label: 'retry', | |
onPressed: () { | |
// Code to execute. or you can simply refresh your page you can also include an image | |
setState(() { | |
}); | |
}, | |
), | |
), | |
); | |
print("No internet connection"); | |
} |