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 checkConnectivity() async { var connectivityResult = await Connectivity().checkConnectivity(); _isConnected = connectivityResult != ConnectivityResult.none; notifyListeners(); } }