๐Ÿš€ Network Speed

Banner Platform Pub

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
Current Speed History Speed Test

๐Ÿง  How It Works

Android Implementation

  • Uses Android's ConnectivityManager and NetworkCapabilities 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

Libraries

network_speed