I am creating a new Flutter project.
I would like to check the internet connectivity status for the whole application using Provider.
I have included both packages "connectivity" and "provider" in the pubspec.yaml file.
Then I have changed main.dart as follow, to include a streamprovider for Connectivity plugin:
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
StreamProvider(
create: (context) => Connectivity().onConnectivityChanged),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'My New App',
theme: ThemeData(
backgroundColor: Colors.white,
),
home: MyHomePage(title: 'My New App Login'),
),
);
}
}
What should I do on every new class where I want to check the internet connectivity status?
I know I have to instatiate the provider:
var connectionStatus;
connectionStatus = Provider.of<ConnectivityResult>(context);
but then, what should I do to listen to the connectivity status on every class?

