I am trying to add network connectivity validation to flutter application , I am using go_router for routing and navigation . I want to push user to other page if he is not connected to internet. I was trying to use connectivity_plus for checking network connection. can we use streamBuilder or any other thing to check connection continuously while using the application.
I tried building Streambuilder with navigation bar widget but is there any better way of doing this.
Following is code example of body part of navigation widget about how I built using streamBuilder:
body: StreamBuilder(
stream: Connectivity().onConnectivityChanged,
builder: (context, AsyncSnapshot<ConnectivityResult> snapshot) {
print(snapshot.toString());
if (snapshot.hasData) {
ConnectivityResult? result = snapshot.data;
if (result == ConnectivityResult.mobile &&
result == ConnectivityResult.wifi) {
return _pages[_currentIndex];
} else {
return NOTConnected();
}
} else {
return NOTConnected();
}
},
),
This is not working as expected .
How can we use this in go_router routes ?