title: How to check internet connection globally and show no connection screen
body: <p>I use <a href="https://pub.dev/packages/connectivity" rel="nofollow noreferrer">connectivity</a> package in my project to check internet connection.</p>
  <p>File <code>main.dart</code> code:</p>
  <pre><code>StreamProvider&lt;ConnectivityResult&gt;(
      create: (context) =&gt;
          InternetConnectionService().connectionStatusController.stream,
      child: MaterialApp(
  .....
  </code></pre>
  <p>And on each screen I check internet connection like this:</p>
  <pre><code>bool hasConnection;
  
  void checkConnectivity(context) async {
    var connectivityResult = Provider.of&lt;ConnectivityResult&gt;(context);
    if (connectivityResult == ConnectivityResult.none ||
        connectivityResult == null) {
      setState(() {
        hasConnection = false;
      });
    } else {
      setState(() {
        hasConnection = true;
      });
    }
  }
  
  Widget build(BuildContext context) {
    checkConnectivity(context);
    return hasConnection == true 
      ? Scaffold() 
      : NoInternetScreen();
  }
  </code></pre>
  <p>How I check connection globally instead on each screen from root or one widget and show no connection screen?</p>