Skip to content

Instantly share code, notes, and snippets.

@Shubham-Narkhede
Created January 30, 2023 07:18
Show Gist options
  • Save Shubham-Narkhede/49c059416c58d07c11b9d191dbbdeb66 to your computer and use it in GitHub Desktop.
Save Shubham-Narkhede/49c059416c58d07c11b9d191dbbdeb66 to your computer and use it in GitHub Desktop.
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: Connectivity().onConnectivityChanged,
builder: (context, AsyncSnapshot<ConnectivityResult> snapshot) {
return snapshot.data == ConnectivityResult.mobile ||
snapshot.data == ConnectivityResult.wifi
? MaterialApp(
title: 'Flutter Stateless Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Online'),
debugShowCheckedModeBanner: false,
)
: MaterialApp(
title: 'Flutter Stateless Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Offline'),
debugShowCheckedModeBanner: false,
); // another material app for showing user he is offline
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment