1

I want to check the internet on every page in my flutter app how I can do that without repeating the same code on every screen? here is my code

bool internet = true;

  @override
  void initState() {
    countryController.text = "+961";
    Connectivity().onConnectivityChanged.listen((connectionState) {
      if (connectionState == ConnectivityResult.none) {
        setState(() {
          internet = false;
        });
        // valueNotifierBook.incrementNotifier();
      } else {
        setState(() {
          internet = true;
        });
      }
    });
    super.initState();
  }
Adriaan
  • 17,741
  • 7
  • 42
  • 75
sam
  • 21
  • 5
  • You can review this post https://stackoverflow.com/questions/49648022/check-whether-there-is-an-internet-connection-available-on-flutter-app – Vu Thanh Nov 24 '22 at 08:56

0 Answers0