daily pastebin goal
44%
SHARE
TWEET

Connect Firebase

rikiyanuar Mar 13th, 2019 (edited) 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'dart:async';
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:/Component/fade_transition.dart';
  5. import 'package:/cek_login.dart';
  6. import 'package:firebase_database/firebase_database.dart';
  7. import 'package:flutter_account_kit/flutter_account_kit.dart';
  8. import 'package:font_awesome_flutter/font_awesome_flutter.dart';
  9. import 'package:package_info/package_info.dart';
  10. import 'package:shared_preferences/shared_preferences.dart';
  11. import 'package:url_launcher/url_launcher.dart';
  12.  
  13. class SplashScreen extends StatefulWidget {
  14.   @override
  15.   _SplashScreenState createState() => _SplashScreenState();
  16. }
  17.  
  18. final versi = FirebaseDatabase.instance.reference().child('versi');
  19. final maintenance = FirebaseDatabase.instance.reference().child('maintenance');
  20.  
  21. class _SplashScreenState extends State<SplashScreen> {
  22.   StreamSubscription<Event> _onVersi;
  23.   StreamSubscription<Event> _onMaintenance;
  24.   bool _isMaintenance = false, _isUpdate = false;
  25.   String currVersi = "";
  26.  
  27.   @override
  28.   void initState() {
  29.     super.initState();
  30.     cekLogout();
  31.     // getSimInfo();
  32.  
  33.     _onVersi = versi.onValue.listen(_onValueVersi);
  34.     _onMaintenance = maintenance.onValue.listen(_onValueMaintenance);
  35.  
  36.     PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
  37.       setState(() {
  38.         currVersi = packageInfo.version;
  39.       });
  40.     });
  41.   }
  42.  
  43.   void _onValueVersi(Event event) {
  44.     if (currVersi != event.snapshot.value) {
  45.       if (mounted) {
  46.         setState(() {
  47.           _isUpdate = true;
  48.         });
  49.       }
  50.     } else {
  51.       setState(() {
  52.         _isUpdate = false;
  53.       });
  54.       navigationPage();
  55.     }
  56.   }
  57.  
  58.   void _onValueMaintenance(Event event) {
  59.     if (mounted) {
  60.       setState(() {
  61.         _isMaintenance = event.snapshot.value;
  62.       });
  63.       navigationPage();
  64.     }
  65.   }
  66.  
  67.   void navigationPage() {
  68.     // print(_isMaintenance.toString()+" - "+_isUpdate.toString());
  69.     Future.delayed(Duration(seconds: 3)).then((_) {
  70.       if (_isMaintenance == false && _isUpdate == false) {
  71.         Navigator.pushAndRemoveUntil(context, FadeRoute(widget: CekLogin()),
  72.             (Route<dynamic> route) => false);
  73.       }
  74.     });
  75.   }
  76.  
  77.   @override
  78.   void dispose() {
  79.     _onVersi.cancel();
  80.     _onMaintenance.cancel();
  81.     super.dispose();
  82.   }
  83.  
  84.   @override
  85.   Widget build(BuildContext context) {
  86.     return Scaffold(
  87.       body: _isMaintenance
  88.           ? BuildMaintenance()
  89.           : _isUpdate ? BuildUpdate(launch: _launch) : BuildSplash(),
  90.     );
  91.   }
  92.  
  93.  
  94. }
  95.  
  96. class BuildSplash extends StatelessWidget {
  97.   @override
  98.   Widget build(BuildContext context) {
  99.     return Container(
  100.         height: double.infinity,
  101.         width: double.infinity,
  102.         alignment: Alignment(0.0, 0.0),
  103.         decoration: BoxDecoration(
  104.           gradient: LinearGradient(
  105.             begin: FractionalOffset.topLeft,
  106.             end: FractionalOffset.bottomRight,
  107.             colors: <Color>[
  108.               Colors.cyan[600],
  109.               Colors.cyan[800],
  110.             ],
  111.           ),
  112.         ),
  113.         padding: EdgeInsets.all(48.0),
  114.         child: Image.asset(
  115.           "assets/logo_putih.png",
  116.           fit: BoxFit.cover,
  117.         ));
  118.   }
  119. }
  120.  
  121. class BuildMaintenance extends StatelessWidget {
  122.   @override
  123.   Widget build(BuildContext context) {
  124.     return Container(
  125.       height: double.infinity,
  126.       width: double.infinity,
  127.       decoration: BoxDecoration(
  128.         gradient: LinearGradient(
  129.           begin: FractionalOffset.topLeft,
  130.           end: FractionalOffset.bottomRight,
  131.           colors: <Color>[
  132.             Colors.cyan[600],
  133.             Colors.cyan[800],
  134.           ],
  135.         ),
  136.       ),
  137.       child: Column(
  138.         mainAxisAlignment: MainAxisAlignment.center,
  139.         children: <Widget>[
  140.           Padding(
  141.             padding: EdgeInsets.symmetric(horizontal: 58.0),
  142.             child: Image.asset(
  143.               "assets/logo_putih.png",
  144.               fit: BoxFit.cover,
  145.             ),
  146.           ),
  147.           Container(
  148.             padding: EdgeInsets.symmetric(horizontal: 35.0),
  149.             margin: EdgeInsets.only(top: 40.0),
  150.             child: Text(
  151.               "Aplikasi sedang dalam perbaikan.\nMohon kembali beberapa saat lagi.",
  152.               style: TextStyle(fontSize: 17.0, color: Colors.white),
  153.               textAlign: TextAlign.center,
  154.             ),
  155.           )
  156.         ],
  157.       ),
  158.     );
  159.   }
  160. }
  161.  
  162. class BuildUpdate extends StatelessWidget {
  163.   final launch;
  164.  
  165.   const BuildUpdate({Key key, this.launch}) : super(key: key);
  166.  
  167.   @override
  168.   Widget build(BuildContext context) {
  169.     return Container(
  170.       height: double.infinity,
  171.       width: double.infinity,
  172.       alignment: Alignment(0.0, 0.0),
  173.       decoration: BoxDecoration(
  174.         gradient: LinearGradient(
  175.           begin: FractionalOffset.topLeft,
  176.           end: FractionalOffset.bottomRight,
  177.           colors: <Color>[
  178.             Colors.cyan[600],
  179.             Colors.cyan[800],
  180.           ],
  181.         ),
  182.       ),
  183.       child: Column(
  184.         mainAxisAlignment: MainAxisAlignment.center,
  185.         children: <Widget>[
  186.           Padding(
  187.             padding: EdgeInsets.symmetric(horizontal: 58.0),
  188.             child: Image.asset(
  189.               "assets/logo_putih.png",
  190.               fit: BoxFit.cover,
  191.             ),
  192.           ),
  193.           Container(
  194.             padding: EdgeInsets.symmetric(horizontal: 35.0),
  195.             margin: EdgeInsets.only(top: 40.0),
  196.             child: Text(
  197.               "Versi baru tersedia.\nSilahkan Update ke versi terbaru.",
  198.               style: TextStyle(fontSize: 17.0, color: Colors.white),
  199.               textAlign: TextAlign.center,
  200.             ),
  201.           ),
  202.           Container(
  203.             margin: EdgeInsets.only(top: 30.0),
  204.             padding: EdgeInsets.symmetric(horizontal: 120.0),
  205.             child: FlatButton(
  206.               onPressed: launch,
  207.               padding: EdgeInsets.all(15.0),
  208.               child: Row(
  209.                 mainAxisAlignment: MainAxisAlignment.center,
  210.                 children: <Widget>[
  211.                   Icon(
  212.                     FontAwesomeIcons.googlePlay,
  213.                     size: 18.0,
  214.                   ),
  215.                   Padding(
  216.                     padding: EdgeInsets.only(left: 15.0),
  217.                     child: Text(
  218.                       "Update",
  219.                       style: TextStyle(fontSize: 20.0),
  220.                     ),
  221.                   ),
  222.                 ],
  223.               ),
  224.               textColor: Colors.white,
  225.               color: Colors.teal[300],
  226.             ),
  227.           )
  228.         ],
  229.       ),
  230.     );
  231.   }
  232. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top