How to show a widget throughout app based on condition?

Viewed 66

I show a snackbar if network connectivity isn't there. I have created a separate stateful widget to check the connectivity and show the bar but I will have to add it to all the screens and so was wondering if there is a better way to include it in all the screens somehow.

1 Answers

Your question is not clear, but I think you want to show the snack bar if the network is not available,? to get the connectivity status you can use this,

var connectivityResult = await (new Connectivity().checkConnectivity());
if (connectivityResult == ConnectivityResult.mobile ||
    connectivityResult == ConnectivityResult.wifi) {
} else {
  Scaffold(
    appBar: AppBar(
      title: Text('SnackBar Demo'),
    ),
    body: Center(
      child: Text('No  Internet'),
    ), // You'll fill this in below!
  );
}
Related