Created
January 30, 2023 07:18
-
-
Save Shubham-Narkhede/49c059416c58d07c11b9d191dbbdeb66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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