23 lines
678 B
Dart
23 lines
678 B
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
||
|
|
||
|
class ConnectivityProvider with ChangeNotifier {
|
||
|
bool _isConnected = true; // Initial value, assuming we have internet.
|
||
|
|
||
|
bool get isConnected => _isConnected;
|
||
|
|
||
|
ConnectivityProvider() {
|
||
|
checkConnectivity();
|
||
|
Connectivity().onConnectivityChanged.listen((result) {
|
||
|
_isConnected = result != ConnectivityResult.none;
|
||
|
notifyListeners();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
Future<void> checkConnectivity() async {
|
||
|
var connectivityResult = await Connectivity().checkConnectivity();
|
||
|
_isConnected = connectivityResult != ConnectivityResult.none;
|
||
|
notifyListeners();
|
||
|
}
|
||
|
}
|