import 'dart:async'; import 'dart:io'; import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:fluro/fluro.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bugly/flutter_bugly.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:liftmanager/internal/bbs/provide/websocket.dart'; import 'package:liftmanager/internal/home/splash_page.dart'; import 'package:liftmanager/privacy_policy_page.dart'; import 'package:liftmanager/provider/theme_provider.dart'; import 'package:liftmanager/routers/application.dart'; import 'package:liftmanager/routers/routers.dart'; import 'package:oktoast/oktoast.dart'; import 'package:provider/provider.dart'; import 'package:jpush_flutter/jpush_flutter.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:umeng_common_sdk/umeng_common_sdk.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); FlutterBugly.postCatchedException(() async { // 强制竖屏 SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); // OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp); // 透明状态栏 if (Platform.isAndroid) { SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(statusBarColor: Colors.transparent); SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle); } /// Fluttify引擎的日志 await enableFluttifyLog(false); // 关闭log SharedPreferences sharedPref = await SharedPreferences.getInstance(); bool isAree = sharedPref.getBool('isAreeYs') ?? false; runZoned( () { runApp( MultiProvider( providers: [ ChangeNotifierProvider( create: (BuildContext context) => WebSocketProvide(), ), ], child: MyApp( isAree: isAree, ), ), ); }, onError: (Object error, StackTrace stack) { print('In-zoned error: $error'); print('In-zoned stack: $stack'); }, ); }); } final GlobalKey navigatorKey = new GlobalKey(); class MyApp extends StatefulWidget { final bool isAree; MyApp({this.isAree}) { final router = FluroRouter(); Routers.configureRouters(router); Application.router = router; } @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { // class _MyAppState extends State with AmapLocationDisposeMixin { StreamSubscription _receiveDeviceToken; // StreamSubscription _receiveMessage; // StreamSubscription _receiveNotification; StreamSubscription _launchNotification; StreamSubscription _resumeNotification; final JPush jpush = JPush(); @override void initState() { // TODO: implement initState super.initState(); // _receiveDeviceToken = // _push.receiveDeviceToken().listen(_handleReceiveDeviceToken); // _receiveMessage = _push.receiveMessage().listen(_handleReceiveMessage); // _receiveNotification = // _push.receiveNotification().listen(_handleReceiveNotification); // _launchNotification = // _push.launchNotification().listen(_handleLaunchNotification); // _resumeNotification = // _push.resumeNotification().listen(_handleResumeNotification); // _push.areNotificationsEnabled().then((l) { // print("是否开启通知:$l"); // }); // UmengCommonSdk.setPageCollectionModeAuto(); // // UmengCommonSdk.initCommon( // '606d0db3de41b946ab3fe2bf', '60711efede41b946ab45daad', 'App Store'); // // UmengCommonSdk.setPageCollectionModeManual(); // _push.startWork(enableDebug: false); } // void _handleReceiveDeviceToken(String deviceToken) async { // if (deviceToken != null) { // print( // 'receiveDeviceToken: $deviceToken - ${await _push.getDeviceToken()}'); // _showTips('receiveDeviceToken', deviceToken); // } // } // // void _handleReceiveMessage(Message message) { // print( // 'receiveMessage: ${message.title} - ${message.content} - ${message.customContent}'); // _showTips('receiveMessage', // '${message.title} - ${message.content} - ${message.customContent}'); // } // // void _handleReceiveNotification(Message notification) { // print( // 'receiveNotification: ${notification.title} - ${notification.content} - ${notification.customContent}'); // _showTips('receiveNotification', // '${notification.title} - ${notification.content} - ${notification.customContent}'); // } void _handleLaunchNotification(String customContent) { print('launchNotification: $customContent'); _showTips('launchNotification', customContent); } void _handleResumeNotification(String customContent) { print('resumeNotification: $customContent'); _showTips('resumeNotification', customContent); } void _showTips(String title, String content) { // showToast(content); } @override void dispose() { if (_receiveDeviceToken != null) { _receiveDeviceToken.cancel(); } // if (_receiveMessage != null) { // _receiveMessage.cancel(); // } // if (_receiveNotification != null) { // _receiveNotification.cancel(); // } if (_launchNotification != null) { _launchNotification.cancel(); } if (_resumeNotification != null) { _resumeNotification.cancel(); } super.dispose(); } @override Widget build(BuildContext context) { return OKToast( child: ChangeNotifierProvider( create: (_) => ThemeProvider(), child: Consumer( builder: (_, provider, __) { return MaterialApp( navigatorKey: navigatorKey, title: '电梯管家', //showPerformanceOverlay: true, //显示性能标签 debugShowCheckedModeBanner: false, //checkerboardRasterCacheImages: true, theme: provider.getTheme(), darkTheme: provider.getTheme(isDarkMode: true), home: widget.isAree ? SplashPage() : PrivacyPolicyPage(), onGenerateRoute: Application.router.generator, localizationsDelegates: const [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: const [ // Locale('zh', 'CH'), // Locale('en', 'US') const Locale('zh', 'Hans'), // China const Locale('zh', ''), // China ]); }, ), ), backgroundColor: Colors.black54, textPadding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0), radius: 20.0, position: ToastPosition.bottom); } }