This package allows your Flutter app to detect the current network type, supporting 2G, 3G, 4G, 5G, and Wi-Fi.
"network_type_detector" is a Flutter package inspired by the connection_network_type library. This package has been updated to support configurations for the Android namespace. Additionally, it is designed to use specific Android APIs based on different versions of Android. This approach allows the package to better adapt to various versions of the Android system, providing accurate network connection type detection. This is particularly important for the development of cross-platform applications.
- To detect the current Network Type:
// If this plugin is used on Android, request the READ_PHONE_STATE permission.
if(Platform.isAndroid) {
await Permission.phone.request();
}
NetworkStatus networkStatus = await ConnectionNetworkType().currentNetworkStatus();
switch(networkStatus) {
case NetworkStatus.unreachable:
// unreachable
case NetworkStatus.wifi:
// wifi
case NetworkStatus.mobile2G:
// 2G
case NetworkStatus.mobile3G:
// 3G
case NetworkStatus.mobile4G:
// 4G
case NetworkStatus.mobile5G:
// 5G
case NetworkStatus.otherMoblie:
// other connection
}
- To listen changes on Network Type:
ConnectionNetworkType().onNetworkStateChanged
.listen((NetworkStatus networkStatus) {
// Trigger one function or manage state from here
});