main.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import 'dart:async';
  2. import 'dart:io';
  3. import 'package:amap_map_fluttify/amap_map_fluttify.dart';
  4. import 'package:fluro/fluro.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter/services.dart';
  7. import 'package:flutter_bugly/flutter_bugly.dart';
  8. import 'package:flutter_localizations/flutter_localizations.dart';
  9. import 'package:liftmanager/internal/bbs/provide/websocket.dart';
  10. import 'package:liftmanager/internal/home/splash_page.dart';
  11. import 'package:liftmanager/privacy_policy_page.dart';
  12. import 'package:liftmanager/provider/theme_provider.dart';
  13. import 'package:liftmanager/routers/application.dart';
  14. import 'package:liftmanager/routers/routers.dart';
  15. import 'package:oktoast/oktoast.dart';
  16. import 'package:provider/provider.dart';
  17. import 'package:jpush_flutter/jpush_flutter.dart';
  18. import 'package:shared_preferences/shared_preferences.dart';
  19. import 'package:umeng_common_sdk/umeng_common_sdk.dart';
  20. void main() {
  21. WidgetsFlutterBinding.ensureInitialized();
  22. FlutterBugly.postCatchedException(() async {
  23. // 强制竖屏
  24. SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  25. // OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
  26. // 透明状态栏
  27. if (Platform.isAndroid) {
  28. SystemUiOverlayStyle systemUiOverlayStyle =
  29. SystemUiOverlayStyle(statusBarColor: Colors.transparent);
  30. SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  31. }
  32. /// Fluttify引擎的日志
  33. await enableFluttifyLog(false); // 关闭log
  34. SharedPreferences sharedPref = await SharedPreferences.getInstance();
  35. bool isAree = sharedPref.getBool('isAreeYs') ?? false;
  36. runZoned(
  37. () {
  38. runApp(
  39. MultiProvider(
  40. providers: [
  41. ChangeNotifierProvider(
  42. create: (BuildContext context) => WebSocketProvide(),
  43. ),
  44. ],
  45. child: MyApp(
  46. isAree: isAree,
  47. ),
  48. ),
  49. );
  50. },
  51. onError: (Object error, StackTrace stack) {
  52. print('In-zoned error: $error');
  53. print('In-zoned stack: $stack');
  54. },
  55. );
  56. });
  57. }
  58. final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
  59. class MyApp extends StatefulWidget {
  60. final bool isAree;
  61. MyApp({this.isAree}) {
  62. final router = FluroRouter();
  63. Routers.configureRouters(router);
  64. Application.router = router;
  65. }
  66. @override
  67. _MyAppState createState() => _MyAppState();
  68. }
  69. class _MyAppState extends State<MyApp> {
  70. // class _MyAppState extends State<MyApp> with AmapLocationDisposeMixin {
  71. StreamSubscription<String> _receiveDeviceToken;
  72. // StreamSubscription<Message> _receiveMessage;
  73. // StreamSubscription<Message> _receiveNotification;
  74. StreamSubscription<String> _launchNotification;
  75. StreamSubscription<String> _resumeNotification;
  76. final JPush jpush = JPush();
  77. @override
  78. void initState() {
  79. // TODO: implement initState
  80. super.initState();
  81. // _receiveDeviceToken =
  82. // _push.receiveDeviceToken().listen(_handleReceiveDeviceToken);
  83. // _receiveMessage = _push.receiveMessage().listen(_handleReceiveMessage);
  84. // _receiveNotification =
  85. // _push.receiveNotification().listen(_handleReceiveNotification);
  86. // _launchNotification =
  87. // _push.launchNotification().listen(_handleLaunchNotification);
  88. // _resumeNotification =
  89. // _push.resumeNotification().listen(_handleResumeNotification);
  90. // _push.areNotificationsEnabled().then((l) {
  91. // print("是否开启通知:$l");
  92. // });
  93. // UmengCommonSdk.setPageCollectionModeAuto();
  94. //
  95. // UmengCommonSdk.initCommon(
  96. // '606d0db3de41b946ab3fe2bf', '60711efede41b946ab45daad', 'App Store');
  97. //
  98. // UmengCommonSdk.setPageCollectionModeManual();
  99. // _push.startWork(enableDebug: false);
  100. }
  101. // void _handleReceiveDeviceToken(String deviceToken) async {
  102. // if (deviceToken != null) {
  103. // print(
  104. // 'receiveDeviceToken: $deviceToken - ${await _push.getDeviceToken()}');
  105. // _showTips('receiveDeviceToken', deviceToken);
  106. // }
  107. // }
  108. //
  109. // void _handleReceiveMessage(Message message) {
  110. // print(
  111. // 'receiveMessage: ${message.title} - ${message.content} - ${message.customContent}');
  112. // _showTips('receiveMessage',
  113. // '${message.title} - ${message.content} - ${message.customContent}');
  114. // }
  115. //
  116. // void _handleReceiveNotification(Message notification) {
  117. // print(
  118. // 'receiveNotification: ${notification.title} - ${notification.content} - ${notification.customContent}');
  119. // _showTips('receiveNotification',
  120. // '${notification.title} - ${notification.content} - ${notification.customContent}');
  121. // }
  122. void _handleLaunchNotification(String customContent) {
  123. print('launchNotification: $customContent');
  124. _showTips('launchNotification', customContent);
  125. }
  126. void _handleResumeNotification(String customContent) {
  127. print('resumeNotification: $customContent');
  128. _showTips('resumeNotification', customContent);
  129. }
  130. void _showTips(String title, String content) {
  131. // showToast(content);
  132. }
  133. @override
  134. void dispose() {
  135. if (_receiveDeviceToken != null) {
  136. _receiveDeviceToken.cancel();
  137. }
  138. // if (_receiveMessage != null) {
  139. // _receiveMessage.cancel();
  140. // }
  141. // if (_receiveNotification != null) {
  142. // _receiveNotification.cancel();
  143. // }
  144. if (_launchNotification != null) {
  145. _launchNotification.cancel();
  146. }
  147. if (_resumeNotification != null) {
  148. _resumeNotification.cancel();
  149. }
  150. super.dispose();
  151. }
  152. @override
  153. Widget build(BuildContext context) {
  154. return OKToast(
  155. child: ChangeNotifierProvider<ThemeProvider>(
  156. create: (_) => ThemeProvider(),
  157. child: Consumer<ThemeProvider>(
  158. builder: (_, provider, __) {
  159. return MaterialApp(
  160. navigatorKey: navigatorKey,
  161. title: '电梯管家',
  162. //showPerformanceOverlay: true, //显示性能标签
  163. debugShowCheckedModeBanner: false,
  164. //checkerboardRasterCacheImages: true,
  165. theme: provider.getTheme(),
  166. darkTheme: provider.getTheme(isDarkMode: true),
  167. home: widget.isAree ? SplashPage() : PrivacyPolicyPage(),
  168. onGenerateRoute: Application.router.generator,
  169. localizationsDelegates: const [
  170. GlobalMaterialLocalizations.delegate,
  171. GlobalWidgetsLocalizations.delegate,
  172. GlobalCupertinoLocalizations.delegate,
  173. ],
  174. supportedLocales: const [
  175. // Locale('zh', 'CH'),
  176. // Locale('en', 'US')
  177. const Locale('zh', 'Hans'), // China
  178. const Locale('zh', ''), // China
  179. ]);
  180. },
  181. ),
  182. ),
  183. backgroundColor: Colors.black54,
  184. textPadding:
  185. const EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0),
  186. radius: 20.0,
  187. position: ToastPosition.bottom);
  188. }
  189. }