network_speed 0.0.2
network_speed: ^0.0.2 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
ConnectivityManagerandNetworkCapabilitiesAPIs for real-time network speed detection - Implements
WifiManagerfor WiFi signal strength - All operations run on background threads to prevent UI freezing
iOS Implementation #
- Implements
URLSessionDataDelegatefor accurate download and upload speed measurements - Uses
SCNetworkReachabilityFlagsfor 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
