Guest User

main.dart

a guest
Jun 18th, 2021
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 12.25 KB | None | 0 0
  1. import 'dart:async';
  2. import 'dart:ui';
  3. import 'package:data_connection_checker/data_connection_checker.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:mfollower/noInternet.dart';
  7. import 'package:shared_preferences/shared_preferences.dart';
  8. import 'package:url_launcher/url_launcher.dart';
  9. import 'package:webview_flutter/webview_flutter.dart';
  10. import 'info.dart';
  11.  
  12. void main() {
  13.   runApp(MyApp());
  14. }
  15. //////////////////
  16.  
  17. /////////////////
  18. class MyApp extends StatelessWidget {
  19.   // This widget is the root of your application.
  20.   @override
  21.   Widget build(BuildContext context) {
  22.     return MaterialApp(
  23.       title: 'Flutter Stateless Demo',
  24.       theme: ThemeData(
  25.         primarySwatch: Colors.blue,
  26.       ),
  27.       home: Homepage(),
  28.       debugShowCheckedModeBanner: false,
  29.     );
  30.   }
  31. }
  32.  
  33. class Homepage extends StatefulWidget {
  34.   Homepage({Key key}) : super(key: key);
  35.  
  36.   @override
  37.   _HomepageState createState() => _HomepageState();
  38. }
  39.  
  40. class _HomepageState extends State<Homepage> {
  41.   final keyIsFirstLoaded = 'is_first_loaded';
  42.   num position = 1;
  43.  
  44.   // @override
  45.   // void initState() {
  46.   //   super.initState();
  47.   //   if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
  48.   // }
  49. //Internet connection check code start
  50.   StreamSubscription<DataConnectionStatus> listener;
  51.   var Internetstatus = "Unknown";
  52.   @override
  53.   void initState() {
  54.     // TODO: implement initState
  55.     super.initState();
  56. //    _updateConnectionStatus();
  57.     CheckInternet();
  58.   }
  59.  
  60.   @override
  61.   void dispose() {
  62.     // TODO: implement dispose
  63.     listener.cancel();
  64.     super.dispose();
  65.   }
  66.  
  67.   CheckInternet() async {
  68.     // Simple check to see if we have internet
  69.     print("The statement 'this machine is connected to the Internet' is: ");
  70.     print(await DataConnectionChecker().hasConnection);
  71.     // returns a bool
  72.  
  73.     // We can also get an enum instead of a bool
  74.     print("Current status: ${await DataConnectionChecker().connectionStatus}");
  75.     // prints either DataConnectionStatus.connected
  76.     // or DataConnectionStatus.disconnected
  77.  
  78.     // This returns the last results from the last call
  79.     // to either hasConnection or connectionStatus
  80.     print("Last results: ${DataConnectionChecker().lastTryResults}");
  81.  
  82.     // actively listen for status updates
  83.     listener = DataConnectionChecker().onStatusChange.listen((status) {
  84.       switch (status) {
  85.         case DataConnectionStatus.connected:
  86.           Internetstatus="Connectd TO THe Internet";
  87.           print('Data connection is available.');
  88.           setState(() {
  89. Homepage();
  90.           });
  91.           break;
  92.         case DataConnectionStatus.disconnected:
  93.           Internetstatus="No Data Connection";
  94.           print('You are disconnected from the internet.');
  95.           setState(() {
  96. NoInternet();
  97.           });
  98.           break;
  99.       }
  100.     });
  101.  
  102.     // close listener after 30 seconds, so the program doesn't run forever
  103. //    await Future.delayed(Duration(seconds: 30));
  104. //    await listener.cancel();
  105.     return await DataConnectionChecker().connectionStatus;
  106.   }
  107.   //Internet connection check code end
  108.  
  109.   @override
  110.   Widget build(BuildContext context) {
  111.     Future.delayed(Duration.zero, () => showDialogIfFirstLoaded(context));
  112.     return Scaffold(
  113.       appBar: AppBar(
  114.         title: Text('my app'),
  115.         flexibleSpace: Container(
  116.           decoration: BoxDecoration(
  117.             gradient: LinearGradient(
  118.               begin: Alignment.topLeft,
  119.               end: Alignment.bottomRight,
  120.               colors: <Color>[Colors.pinkAccent, Colors.blueAccent],
  121.             ),
  122.           ),
  123.         ),
  124.         actions: <Widget>[
  125.           IconButton(
  126.             icon: Icon(Icons.home),
  127.             onPressed: () {
  128.               Navigator.push(
  129.                 context,
  130.                 MaterialPageRoute(builder: (context) => Homepage()),
  131.               );
  132.             },
  133.           ),
  134.           IconButton(
  135.               icon: Icon(Icons.refresh),
  136.               onPressed: () {
  137.                 Navigator.push(context,
  138.                     MaterialPageRoute(builder: (context) => Homepage()));
  139.               }),
  140.           IconButton(
  141.               icon: Icon(Icons.help_outline_outlined),
  142.               onPressed: () async {
  143.                 const url = 'https://google.com/';
  144.                 if (await canLaunch(url)) {
  145.                   await launch(
  146.                     url,
  147.                   );
  148.                 } else {
  149.                   throw 'Could not launch $url';
  150.                 }
  151.               }),
  152.         ],
  153.         // automaticallyImplyLeading: false,
  154.       ),
  155.       drawer: Drawer(
  156.         child: ListView(
  157.           padding: EdgeInsets.zero,
  158.           children: <Widget>[
  159.             DrawerHeader(
  160.               decoration: BoxDecoration(
  161.                 color: Colors.white,
  162.               ),
  163.               child: Row(
  164.                 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  165.                 children: <Widget>[
  166.                   Image.asset("assets/imgs/appIcon.png"),
  167.                   Column(
  168.                     mainAxisAlignment: MainAxisAlignment.center,
  169.                     crossAxisAlignment: CrossAxisAlignment.start,
  170.                     children: <Widget>[
  171.                       Text(
  172.                         "app name",
  173.                         style: TextStyle(
  174.                           color: Colors.black,
  175.                           fontSize: 20.0,
  176.                           fontWeight: FontWeight.bold,
  177.                         ),
  178.                       ),
  179.                       SizedBox(height: 10.0),
  180.                       Text(
  181.                         "Subtitle",
  182.                         style: TextStyle(color: Colors.black),
  183.                       ),
  184.                     ],
  185.                   )
  186.                 ],
  187.               ),
  188.             ),
  189.             ListTile(
  190.               title: Text("Free Likes"),
  191.               leading: Icon(CupertinoIcons.heart),
  192.               onTap: () async {
  193.                 const url = "https://youtube.com";
  194.                 if (await canLaunch(url)) {
  195.                   await launch(
  196.                     url,
  197.                   );
  198.                 } else {
  199.                   throw 'Could not launch $url';
  200.                 }
  201.               },
  202.             ),
  203.             ListTile(
  204.               title: Text("Free Followers"),
  205.               leading: Icon(CupertinoIcons.person_add),
  206.               onTap: () {
  207.                 Navigator.push(context,
  208.                     MaterialPageRoute(builder: (context) => Homepage()));
  209.               },
  210.             ),
  211.             ListTile(
  212.               title: Text("Free Views"),
  213.               leading: Icon(CupertinoIcons.play),
  214.               onTap: () {
  215.                 Navigator.push(context,
  216.                     MaterialPageRoute(builder: (context) => Homepage()));
  217.               },
  218.             ),
  219.             ListTile(
  220.               title: Text("Paid Service"),
  221.               leading: Icon(CupertinoIcons.money_dollar),
  222.               onTap: () {
  223.                 Navigator.push(context,
  224.                     MaterialPageRoute(builder: (context) => Homepage()));
  225.               },
  226.             ),
  227.             ListTile(
  228.               title: Text("About us"),
  229.               leading: Icon(CupertinoIcons.rectangle_stack_person_crop),
  230.               onTap: () {
  231.                 Navigator.push(context,
  232.                     MaterialPageRoute(builder: (context) => Homepage()));
  233.               },
  234.             ),
  235.             ListTile(
  236.               title: Text("Privacy Policy"),
  237.               leading: Icon(CupertinoIcons.doc_text),
  238.               onTap: () {
  239.                 Navigator.push(context,
  240.                     MaterialPageRoute(builder: (context) => Homepage()));
  241.               },
  242.             ),
  243.             ListTile(
  244.               title: Text("Disclaimer"),
  245.               leading: Icon(CupertinoIcons.doc_richtext),
  246.               onTap: () {
  247.                 Navigator.push(context,
  248.                     MaterialPageRoute(builder: (context) => Homepage()));
  249.               },
  250.             ),
  251.             Divider(
  252.               color: Colors.black,
  253.               height: 5,
  254.             ),
  255.             ListTile(
  256.               title: Text("App Info"),
  257.               leading: Icon(Icons.info),
  258.               onTap: () {
  259.                 Navigator.push(context,
  260.                     MaterialPageRoute(builder: (context) => AppInfo()));
  261.               },
  262.             ),
  263.           ],
  264.         ),
  265.       ),
  266.       body: IndexedStack(
  267.         index: position,
  268.         children: <Widget>[
  269.           WebView(
  270.             initialUrl: 'https://google.com',
  271.             // javascriptMode: JavascriptMode.unrestricted,
  272.             onPageStarted: (value) {
  273.               setState(() {
  274.                 position = 1;
  275.               });
  276.             },
  277.             onPageFinished: (value) {
  278.               setState(() {
  279.                 position = 0;
  280.               });
  281.             },
  282.           ),
  283.           Center(
  284.             child: Column(
  285.               mainAxisAlignment: MainAxisAlignment.center,
  286.               children: <Widget>[
  287.                 CircularProgressIndicator(
  288.                   valueColor: AlwaysStoppedAnimation(Colors.pinkAccent),
  289.                 ),
  290.                 Text('Please wait...')
  291.               ],
  292.             ),
  293.           ),
  294.         ],
  295.       ),
  296.       floatingActionButton: FloatingActionButton(
  297.         child: Icon(Icons.help_outline_sharp),
  298.         onPressed: () async {
  299.           const url = 'https://google.com/';
  300.           if (await canLaunch(url)) {
  301.             await launch(
  302.               url,
  303.             );
  304.           } else {
  305.             throw 'Could not launch $url';
  306.           }
  307.         },
  308.       ),
  309.     );
  310.   }
  311.  
  312.   showDialogIfFirstLoaded(BuildContext context) async {
  313.     SharedPreferences prefs = await SharedPreferences.getInstance();
  314.     bool isFirstLoaded = prefs.getBool(keyIsFirstLoaded);
  315.     if (isFirstLoaded == null) {
  316.       showCupertinoDialog(
  317.         context: context,
  318.         builder: (BuildContext context) {
  319.           // return object of type Dialog
  320.           return CupertinoAlertDialog(
  321.             title: new Text("Title"),
  322.             content: new Text("This is one time dialog"),
  323.             actions: <Widget>[
  324.               // usually buttons at the bottom of the dialog
  325.               CupertinoDialogAction(
  326.                 child: Text('Yes'),
  327.                 isDefaultAction: true,
  328.                 isDestructiveAction: true,
  329.                 onPressed: () {
  330.                   // Close the dialog
  331.                   Navigator.of(context).pop();
  332.                   prefs.setBool(keyIsFirstLoaded, false);
  333.                 },
  334.               ),
  335.               CupertinoDialogAction(
  336.                 child: Text('No'),
  337.                 isDefaultAction: false,
  338.                 isDestructiveAction: false,
  339.                 onPressed: () {
  340.                   // Close the dialog
  341.                   Navigator.of(context).pop();
  342.                   prefs.setBool(keyIsFirstLoaded, false);
  343.                 },
  344.               ),
  345.             ],
  346.           );
  347.         },
  348.       );
  349.       showCupertinoDialog(
  350.         context: context,
  351.         builder: (BuildContext context) {
  352.           // return object of type Dialog
  353.           return CupertinoAlertDialog(
  354.             title: new Text("Title"),
  355.             content: new Text("This is one time dialog"),
  356.             actions: <Widget>[
  357.               // usually buttons at the bottom of the dialog
  358.  
  359.               CupertinoDialogAction(
  360.                 child: Text('Yes'),
  361.                 isDefaultAction: true,
  362.                 isDestructiveAction: true,
  363.                 onPressed: () {
  364.                   // Close the dialog
  365.                   Navigator.of(context).pop();
  366.                   prefs.setBool(keyIsFirstLoaded, false);
  367.                 },
  368.               ),
  369.               CupertinoDialogAction(
  370.                 child: Text('No'),
  371.                 isDefaultAction: false,
  372.                 isDestructiveAction: false,
  373.                 onPressed: () {
  374.                   // Close the dialog
  375.                   Navigator.of(context).pop();
  376.                   prefs.setBool(keyIsFirstLoaded, false);
  377.                 },
  378.               ),
  379.             ],
  380.           );
  381.         },
  382.       );
  383.     }
  384.   }
  385. }
  386.  
Advertisement
Add Comment
Please, Sign In to add comment