Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:async';
- import 'dart:ui';
- import 'package:data_connection_checker/data_connection_checker.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:mfollower/noInternet.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:url_launcher/url_launcher.dart';
- import 'package:webview_flutter/webview_flutter.dart';
- import 'info.dart';
- void main() {
- runApp(MyApp());
- }
- //////////////////
- /////////////////
- class MyApp extends StatelessWidget {
- // This widget is the root of your application.
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Stateless Demo',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: Homepage(),
- debugShowCheckedModeBanner: false,
- );
- }
- }
- class Homepage extends StatefulWidget {
- Homepage({Key key}) : super(key: key);
- @override
- _HomepageState createState() => _HomepageState();
- }
- class _HomepageState extends State<Homepage> {
- final keyIsFirstLoaded = 'is_first_loaded';
- num position = 1;
- // @override
- // void initState() {
- // super.initState();
- // if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
- // }
- //Internet connection check code start
- StreamSubscription<DataConnectionStatus> listener;
- var Internetstatus = "Unknown";
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- // _updateConnectionStatus();
- CheckInternet();
- }
- @override
- void dispose() {
- // TODO: implement dispose
- listener.cancel();
- super.dispose();
- }
- CheckInternet() async {
- // Simple check to see if we have internet
- print("The statement 'this machine is connected to the Internet' is: ");
- print(await DataConnectionChecker().hasConnection);
- // returns a bool
- // We can also get an enum instead of a bool
- print("Current status: ${await DataConnectionChecker().connectionStatus}");
- // prints either DataConnectionStatus.connected
- // or DataConnectionStatus.disconnected
- // This returns the last results from the last call
- // to either hasConnection or connectionStatus
- print("Last results: ${DataConnectionChecker().lastTryResults}");
- // actively listen for status updates
- listener = DataConnectionChecker().onStatusChange.listen((status) {
- switch (status) {
- case DataConnectionStatus.connected:
- Internetstatus="Connectd TO THe Internet";
- print('Data connection is available.');
- setState(() {
- Homepage();
- });
- break;
- case DataConnectionStatus.disconnected:
- Internetstatus="No Data Connection";
- print('You are disconnected from the internet.');
- setState(() {
- NoInternet();
- });
- break;
- }
- });
- // close listener after 30 seconds, so the program doesn't run forever
- // await Future.delayed(Duration(seconds: 30));
- // await listener.cancel();
- return await DataConnectionChecker().connectionStatus;
- }
- //Internet connection check code end
- @override
- Widget build(BuildContext context) {
- Future.delayed(Duration.zero, () => showDialogIfFirstLoaded(context));
- return Scaffold(
- appBar: AppBar(
- title: Text('my app'),
- flexibleSpace: Container(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topLeft,
- end: Alignment.bottomRight,
- colors: <Color>[Colors.pinkAccent, Colors.blueAccent],
- ),
- ),
- ),
- actions: <Widget>[
- IconButton(
- icon: Icon(Icons.home),
- onPressed: () {
- Navigator.push(
- context,
- MaterialPageRoute(builder: (context) => Homepage()),
- );
- },
- ),
- IconButton(
- icon: Icon(Icons.refresh),
- onPressed: () {
- Navigator.push(context,
- MaterialPageRoute(builder: (context) => Homepage()));
- }),
- IconButton(
- icon: Icon(Icons.help_outline_outlined),
- onPressed: () async {
- const url = 'https://google.com/';
- if (await canLaunch(url)) {
- await launch(
- url,
- );
- } else {
- throw 'Could not launch $url';
- }
- }),
- ],
- // automaticallyImplyLeading: false,
- ),
- drawer: Drawer(
- child: ListView(
- padding: EdgeInsets.zero,
- children: <Widget>[
- DrawerHeader(
- decoration: BoxDecoration(
- color: Colors.white,
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: <Widget>[
- Image.asset("assets/imgs/appIcon.png"),
- Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(
- "app name",
- style: TextStyle(
- color: Colors.black,
- fontSize: 20.0,
- fontWeight: FontWeight.bold,
- ),
- ),
- SizedBox(height: 10.0),
- Text(
- "Subtitle",
- style: TextStyle(color: Colors.black),
- ),
- ],
- )
- ],
- ),
- ),
- ListTile(
- title: Text("Free Likes"),
- leading: Icon(CupertinoIcons.heart),
- onTap: () async {
- const url = "https://youtube.com";
- if (await canLaunch(url)) {
- await launch(
- url,
- );
- } else {
- throw 'Could not launch $url';
- }
- },
- ),
- ListTile(
- title: Text("Free Followers"),
- leading: Icon(CupertinoIcons.person_add),
- onTap: () {
- Navigator.push(context,
- MaterialPageRoute(builder: (context) => Homepage()));
- },
- ),
- ListTile(
- title: Text("Free Views"),
- leading: Icon(CupertinoIcons.play),
- onTap: () {
- Navigator.push(context,
- MaterialPageRoute(builder: (context) => Homepage()));
- },
- ),
- ListTile(
- title: Text("Paid Service"),
- leading: Icon(CupertinoIcons.money_dollar),
- onTap: () {
- Navigator.push(context,
- MaterialPageRoute(builder: (context) => Homepage()));
- },
- ),
- ListTile(
- title: Text("About us"),
- leading: Icon(CupertinoIcons.rectangle_stack_person_crop),
- onTap: () {
- Navigator.push(context,
- MaterialPageRoute(builder: (context) => Homepage()));
- },
- ),
- ListTile(
- title: Text("Privacy Policy"),
- leading: Icon(CupertinoIcons.doc_text),
- onTap: () {
- Navigator.push(context,
- MaterialPageRoute(builder: (context) => Homepage()));
- },
- ),
- ListTile(
- title: Text("Disclaimer"),
- leading: Icon(CupertinoIcons.doc_richtext),
- onTap: () {
- Navigator.push(context,
- MaterialPageRoute(builder: (context) => Homepage()));
- },
- ),
- Divider(
- color: Colors.black,
- height: 5,
- ),
- ListTile(
- title: Text("App Info"),
- leading: Icon(Icons.info),
- onTap: () {
- Navigator.push(context,
- MaterialPageRoute(builder: (context) => AppInfo()));
- },
- ),
- ],
- ),
- ),
- body: IndexedStack(
- index: position,
- children: <Widget>[
- WebView(
- initialUrl: 'https://google.com',
- // javascriptMode: JavascriptMode.unrestricted,
- onPageStarted: (value) {
- setState(() {
- position = 1;
- });
- },
- onPageFinished: (value) {
- setState(() {
- position = 0;
- });
- },
- ),
- Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- CircularProgressIndicator(
- valueColor: AlwaysStoppedAnimation(Colors.pinkAccent),
- ),
- Text('Please wait...')
- ],
- ),
- ),
- ],
- ),
- floatingActionButton: FloatingActionButton(
- child: Icon(Icons.help_outline_sharp),
- onPressed: () async {
- const url = 'https://google.com/';
- if (await canLaunch(url)) {
- await launch(
- url,
- );
- } else {
- throw 'Could not launch $url';
- }
- },
- ),
- );
- }
- showDialogIfFirstLoaded(BuildContext context) async {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- bool isFirstLoaded = prefs.getBool(keyIsFirstLoaded);
- if (isFirstLoaded == null) {
- showCupertinoDialog(
- context: context,
- builder: (BuildContext context) {
- // return object of type Dialog
- return CupertinoAlertDialog(
- title: new Text("Title"),
- content: new Text("This is one time dialog"),
- actions: <Widget>[
- // usually buttons at the bottom of the dialog
- CupertinoDialogAction(
- child: Text('Yes'),
- isDefaultAction: true,
- isDestructiveAction: true,
- onPressed: () {
- // Close the dialog
- Navigator.of(context).pop();
- prefs.setBool(keyIsFirstLoaded, false);
- },
- ),
- CupertinoDialogAction(
- child: Text('No'),
- isDefaultAction: false,
- isDestructiveAction: false,
- onPressed: () {
- // Close the dialog
- Navigator.of(context).pop();
- prefs.setBool(keyIsFirstLoaded, false);
- },
- ),
- ],
- );
- },
- );
- showCupertinoDialog(
- context: context,
- builder: (BuildContext context) {
- // return object of type Dialog
- return CupertinoAlertDialog(
- title: new Text("Title"),
- content: new Text("This is one time dialog"),
- actions: <Widget>[
- // usually buttons at the bottom of the dialog
- CupertinoDialogAction(
- child: Text('Yes'),
- isDefaultAction: true,
- isDestructiveAction: true,
- onPressed: () {
- // Close the dialog
- Navigator.of(context).pop();
- prefs.setBool(keyIsFirstLoaded, false);
- },
- ),
- CupertinoDialogAction(
- child: Text('No'),
- isDefaultAction: false,
- isDestructiveAction: false,
- onPressed: () {
- // Close the dialog
- Navigator.of(context).pop();
- prefs.setBool(keyIsFirstLoaded, false);
- },
- ),
- ],
- );
- },
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment