mobileapplicationPassvault/lib/api_provider/connectivty_provider.dart

23 lines
678 B
Dart
Raw Normal View History

2024-04-12 05:23:32 +00:00
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();
}
}