network_speed 0.0.1
network_speed: ^0.0.1 copied to clipboard
A Flutter plugin to check internet speed in real-time for both Android and iOS platforms.
๐ Network Speed #
A high-performance Flutter plugin that enables real-time network speed monitoring for both Android and iOS platforms. Check internet connection speed with precision and optimize your app's network-dependent features! โก
โจ Features #
- ๐ฑ Cross-Platform: Works seamlessly on both Android and iOS
- ๐ Real-time Monitoring: Get continuous updates on network speed
- ๐ Network Type Detection: Identify WiFi, mobile data, or no connection
- โฌ๏ธ Download Speed: Accurate download speed measurements in Mbps
- โฌ๏ธ Upload Speed: Precise upload speed measurements in Mbps
- ๐ Signal Strength: WiFi signal strength indicator (1-5)
- ๐งต Background Processing: All operations run on background threads to prevent UI freezing
- ๐งช Speed Tests: Run dedicated download and upload speed tests
- โฑ๏ธ Streaming API: Subscribe to real-time network speed updates
- ๐ Easy Integration: Simple API to quickly add network monitoring to your app
๐ Requirements #
- Flutter: >=3.3.0
- Dart: >=2.18.0
- Android: minSdkVersion 21
- iOS: iOS 12.0 or later
๐ฒ Installation #
Add the following to your pubspec.yaml
:
dependencies:
network_speed: any
Then run:
flutter pub get
๐ง Setup #
Android Setup #
No additional setup is required for Android! The plugin automatically adds the necessary permissions to your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
iOS Setup #
For iOS, add the following to your Info.plist
file:
<key>NSLocalNetworkUsageDescription</key>
<string>This app needs to access your network to measure internet speed.</string>
๐งฉ Usage #
Import the package #
import 'package:network_speed/network_speed.dart';
Get current network type #
NetworkType networkType = await NetworkSpeed.getCurrentNetworkType();
switch (networkType) {
case NetworkType.mobile:
print('๐ฑ Connected to mobile data');
break;
case NetworkType.wifi:
print('๐ถ Connected to WiFi');
break;
case NetworkType.unknown:
print('โ Connection type unknown or offline');
break;
}
Get current download and upload speeds #
// Get instant download speed
double downloadSpeed = await NetworkSpeed.getDownloadSpeed();
print('โฌ๏ธ Download speed: $downloadSpeed Mbps');
// Get instant upload speed
double uploadSpeed = await NetworkSpeed.getUploadSpeed();
print('โฌ๏ธ Upload speed: $uploadSpeed Mbps');
Get all network information at once #
Map<String, dynamic> networkInfo = await NetworkSpeed.getCurrentNetworkSpeed();
print('๐ Network type: ${networkInfo['networkType']}');
print('โฌ๏ธ Download speed: ${networkInfo['downloadSpeed']} Mbps');
print('โฌ๏ธ Upload speed: ${networkInfo['uploadSpeed']} Mbps');
print('๐ถ Signal strength: ${networkInfo['signalStrength']}');
Real-time monitoring with streams #
// Start real-time monitoring with updates every second
StreamSubscription<Map<String, dynamic>> subscription =
NetworkSpeed.getNetworkSpeedStream(interval: 1000).listen((networkInfo) {
print('โฌ๏ธ Download: ${networkInfo['downloadSpeed']} Mbps | โฌ๏ธ Upload: ${networkInfo['uploadSpeed']} Mbps');
});
// Don't forget to cancel the subscription when no longer needed
subscription.cancel();
Run speed tests #
// Show loading indicator
showDialog(context: context, builder: (_) => LoadingDialog());
// Run download speed test
double downloadTestResult = await NetworkSpeed.runDownloadSpeedTest();
print('๐ Download test result: $downloadTestResult Mbps');
// Run upload speed test
double uploadTestResult = await NetworkSpeed.runUploadSpeedTest();
print('๐ Upload test result: $uploadTestResult Mbps');
// Hide loading indicator
Navigator.of(context).pop();
// You can also specify a custom URL for testing
double customDownloadTest = await NetworkSpeed.runDownloadSpeedTest(
testFileUrl: 'https://your-test-file-url.com/file.bin'
);
๐ฑ Example App Screenshots #
Current Speed | History | Speed Test |
๐ง How It Works #
Android Implementation #
- Uses Android's
ConnectivityManager
andNetworkCapabilities
APIs for real-time network speed detection - Implements
WifiManager
for WiFi signal strength - All operations run on background threads to prevent UI freezing
iOS Implementation #
- Implements
URLSessionDataDelegate
for accurate download and upload speed measurements - Uses
SCNetworkReachabilityFlags
for network type detection - All operations run on background queues to prevent UI freezing
๐ Speed Interpretation #
Here's a quick guide to interpret the speed results:
Speed (Mbps) | Quality | Suitable For |
---|---|---|
< 1 | ๐ด Poor | Basic web browsing |
1-5 | ๐ Fair | SD video streaming |
5-20 | ๐ก Good | HD video streaming |
20-50 | ๐ข Very Good | 4K streaming |
50+ | ๐ต Excellent | Multiple 4K streams |
๐ Notes #
- Speed tests require an active internet connection
- Results may vary based on server load and network conditions
- For most accurate results, run multiple tests and average the results
- The plugin uses minimal resources to measure network speed
- All operations run on background threads to prevent UI freezing
๐ค Contributing #
Contributions are welcome! Feel free to submit issues or pull requests if you have any improvements or bug fixes.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
๐ License #
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments #
- Flutter Team for the amazing framework
- All contributors who helped improve this plugin