flutter_connectivity

Last updated:

0 purchases

flutter_connectivity Image
flutter_connectivity Images
Add to Cart

Description:

flutter connectivity

flutter_connectivity #
Constantly monitors and reports changes in connection quality to a specific server or service, built in pure Dart and compatible with Dart and Flutter.
Unlike other packages that only check internet connectivity, this one ensures actual internet access by testing against your designated server.
Features #

✅ Select a server to test against (eg: example.com)
✅ Configure interval for testing
✅ Configure how many failed tests before reporting a connection loss
✅ Set latency thresholds for different connection qualities
✅ Get notified of connection quality changes in real-time
✅ Pause and resume monitoring
✅ Query connection history
✅ Accommodates occasional network hiccups

Use this package when you need to:

monitor connection quality
maintain a stable connection
detect network issues
provide real-time feedback to users (eg: connection quality indicator)

Getting started #

Install the package

Dart
dart pub add flutter_connectivity
copied to clipboard
Flutter
flutter pub add flutter_connectivity
copied to clipboard

Import the package

import 'package:flutter_connectivity/flutter_connectivity.dart';
copied to clipboard

Create a new instance of FlutterConnectivity and start monitoring

// instantiate
FlutterConnectivity connectivity = FlutterConnectivity(endpoint: 'https://example.com');

// listen
connectivity.listenToLatencyChanges((ConnectivityStatus status, int latency) {
print('Connection status: $status, latency: $latency');
});
copied to clipboard
Screenshot #

Compatibility #
Works with all Dart and Flutter (web, mobile, desktop) projects.
Usage #
Create a new instance of FlutterConnectivity
// Modify the endpoint to your server
FlutterConnectivity connectivity = FlutterConnectivity(endpoint: 'https://example.com');
copied to clipboard
Optional: Configure the connectivity instance
connectivity.configure(
// How many failed requests before reporting a connection loss
allowedFailedRequests: 2,

// How often to check the connection
checkInterval: const Duration(seconds: 3),

// What kind of logs appear on your console
logLevel: LogLevel.error,
);
copied to clipboard
Optional: Configure latency thresholds
// Set latency thresholds in milliseconds
connectivity.setLatencyThresholds(
disconnected: 10000,
slow: 5000,
moderate: 2000,
fast: 1000,
);
copied to clipboard
Start the connectivity monitor
connectivity.listenToLatencyChanges((ConnectivityStatus status, int latency) {
print('Connection status: $status, latency: $latency');
});
copied to clipboard
Pause and resume monitoring
// Pause monitoring
connectivity.pause();

// Resume monitoring
connectivity.resume();
copied to clipboard
Get history of latencies with timestamps
Map<int, int> latencies = connectivity.latencyHistory;
copied to clipboard
Stop monitoring
connectivity.dispose();
copied to clipboard
Check out the example for a complete implementation. Run the example using the following command:
dart example/example.dart
copied to clipboard
Additional information #
Report issues and help improve the package on GitHub.
Check API reference for more detailed information.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.