For a starter, You can listen for changes, for example in your onInit method at the top of your app:
connectivity.onConnectivityChanged
// .distinct() (from rxdart package, uncomment if you have this dep)
// debounce time for epileptic network
// .debounceTime(_debounceTime) (from rxjs package)
.listen((c) => setState(() => connectivity = c));
in your build method you can now use the value.
This has to wrap your applications pages, to do so you can set the above listener in a widget that will display the right child depending on the connectivity state and use that widget in the build method:
MaterialApp(
// ...
builder: (ctx, child) => ConnectivityWrapper(child)
)
and in ConnectivityWrapper onInit
connectivity.onConnectivityChanged
// .distinct() (from rxjs package, uncomment if you have this dep)
// .debounceTime(Duration(milliseconds: 400)) (from rxjs package)
.listen((c) => setState(() => connectivity = c));
In connectivity wrapper build:
if (connectivity == ConnectivityResult.none)
return NoInternetPage();
return child;