Advertisement
Guest User

Untitled

a guest
Sep 4th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.47 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:launch_review/launch_review.dart';
  4. import 'package:meeberian_client/components/models/auth.dart';
  5. import 'package:meeberian_client/components/models/version.dart';
  6. import 'package:meeberian_client/constants.dart';
  7. import 'package:meeberian_client/routes.dart';
  8. import 'package:meeberian_client/components/auth_provider.dart';
  9. import 'package:meeberian_client/components/cart_provider.dart';
  10. import 'package:meeberian_client/components/cart_bloc.dart';
  11. import 'package:package_info/package_info.dart';
  12.  
  13. void main() => runApp(new MyApp());
  14.  
  15. class MyApp extends StatelessWidget {
  16.   final BaseAuth _auth = Auth();
  17.   final CartBloc _cartBloc = CartBloc();
  18.  
  19.  
  20.   Future<bool> _confirm(BuildContext context, String dialogTitle, String dialogContent, [bool prompt = false]) async {
  21.     return await showDialog(
  22.       context: context,
  23.       builder: (BuildContext ctx) {
  24.         return AlertDialog(
  25.           title: (dialogTitle.trim().length == 0) ? null : Text(dialogTitle, style: TextStyle(fontWeight: FontWeight.bold)),
  26.           content: Text(
  27.             dialogContent,
  28.             textAlign: TextAlign.center,
  29.           ),
  30.           actions: <Widget>[
  31.             prompt ?
  32.             FlatButton(
  33.               child: new Text("CANCEL", style: TextStyle(color: Colors.red)),
  34.               onPressed: () {
  35.                 Navigator.pop(ctx, false);
  36.               },
  37.             ) : null,
  38.             FlatButton(
  39.               child: new Text("OK", style: TextStyle(color: Colors.red)),
  40.               onPressed: () {
  41.                 Navigator.pop(ctx, true);
  42.               },
  43.             ),
  44.           ],
  45.         );                        
  46.       }      
  47.     );  
  48.   }
  49.  
  50.  
  51.   @override
  52.   Widget build(BuildContext context) {
  53.     PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
  54.       List<String> sTemp = packageInfo.version.split(".");
  55.       List<int> _ver = sTemp.map((v) => int.parse(v));
  56.       appVersion = _ver[0] .toString()+ "." + _ver[1].toString() + (_ver[2] > 9 ? _ver[2].toString() : "0" + _ver[2].toString());
  57.       VersioningController vc = VersioningController();
  58.       vc.checkUpdate().then((_data) {
  59.         if (_data != null) {
  60.           WidgetsBinding.instance.addPostFrameCallback((_) async {
  61.             if (_data.needupdate) {
  62.               _confirm(context, "Info", _data.message).then((onValue) {
  63.                 LaunchReview.launch(androidAppId: "com.meeber.meeberian", iOSAppId: "1459505870");
  64.               });              
  65.             } else {
  66.               _confirm(context, "Info", _data.message, true).then((onValue){
  67.                 if (onValue) {
  68.                   LaunchReview.launch(androidAppId: "com.pasaronline.pembeli", iOSAppId: "1459505870");
  69.                 }
  70.               });
  71.             }
  72.           });
  73.         }
  74.       });
  75.     });
  76.      
  77.     SystemChrome.setEnabledSystemUIOverlays([]);
  78.     return AuthProvider (
  79.       auth: _auth,
  80.       child: CartProvider(
  81.         cartBloc: _cartBloc,
  82.         child: MaterialApp(
  83.           initialRoute: '/switcher',
  84.           routes: getRoutes(),
  85.           debugShowCheckedModeBanner: false,
  86.           showPerformanceOverlay: false,
  87.           title: 'Meeberian',
  88.           theme: new ThemeData(
  89.             primaryColor: Colors.white,
  90.             hintColor: Colors.black,
  91.           ),
  92.         ),
  93.       )
  94.     );    
  95.  
  96.   }
  97. }
  98.  
  99. enum AuthStatus {
  100.   notSignedIn,
  101.   signedIn
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement