123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- import 'dart:async';
- import 'dart:io';
- import 'package:amap_location_flutter_plugin/amap_location_flutter_plugin.dart';
- import 'package:amap_location_flutter_plugin/amap_location_option.dart';
- import 'package:amap_map_fluttify/amap_map_fluttify.dart';
- import 'package:fake_push/fake_push.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/home/splash_page.dart';
- import 'package:liftmanager/provider/theme_provider.dart';
- import 'package:liftmanager/routers/application.dart';
- import 'package:liftmanager/routers/routers.dart';
- import 'package:liftmanager/utils/log_utils.dart';
- import 'package:oktoast/oktoast.dart';
- import 'package:provider/provider.dart' as p;
- void main() {
- WidgetsFlutterBinding.ensureInitialized();
- FlutterBugly.postCatchedException(() async {
- FlutterBugly.init(androidAppId: "ae4e3d567d", iOSAppId: "4f09cdc82c");
- // 透明状态栏
- if (Platform.isAndroid) {
- SystemUiOverlayStyle systemUiOverlayStyle =
- SystemUiOverlayStyle(statusBarColor: Colors.transparent);
- SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
- }
- // AmapCore.init("7724c41be3ebe0cb7e5db4d79edc51b7");
- // await AmapService.init(iosKey: '7724c41be3ebe0cb7e5db4d79edc51b7', androidKey: '9eaae78b5b6b4ba78460b2e2539b798d');
- AmapLocationFlutterPlugin.setApiKey(
- "9eaae78b5b6b4ba78460b2e2539b798d", "7724c41be3ebe0cb7e5db4d79edc51b7");
- /// Fluttify引擎的日志
- await enableFluttifyLog(false); // 关闭log
- Log.init();
- runZoned(() {
- runApp(MyApp());
- }, onError: (Object error, StackTrace stack) {
- print(error);
- print(stack);
- });
- });
- }
- class MyApp extends StatefulWidget {
- final Widget home;
- MyApp({this.home}) {
- final router = Router();
- Routers.configureRouters(router);
- Application.router = router;
- }
- @override
- _MyAppState createState() => _MyAppState();
- }
- class _MyAppState extends State<MyApp> {
- // Map<String, Object> _locationResult;
- // StreamSubscription<Map<String, Object>> _locationListener;
- // AmapLocationFlutterPlugin _locationPlugin = new AmapLocationFlutterPlugin();
- Push _push = Push();
- StreamSubscription<String> _receiveDeviceToken;
- StreamSubscription<Message> _receiveMessage;
- StreamSubscription<Message> _receiveNotification;
- StreamSubscription<String> _launchNotification;
- StreamSubscription<String> _resumeNotification;
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- // _locationListener = _locationPlugin
- // .onLocationChanged()
- // .listen((Map<String, Object> result) {
- // setState(() {
- // _locationResult = result;
- // _locationResult.forEach((key, value) {
- // print('key:$key :');
- // print('value:$value :');
- // });
- // });
- // });
- // if (null != _locationPlugin) {
- // ///开始定位之前设置定位参数
- // _setLocationOption();
- // _locationPlugin.startLocation();
- // }
- // _setLocationOption();
- _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");
- });
- // _push.openNotificationsSettings();
- _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();
- // ///移除定位监听
- // if (null != _locationListener) {
- // _locationListener.cancel();
- // }
- //
- // ///销毁定位
- // if (null != _locationPlugin) {
- // _locationPlugin.destroy();
- // }
- }
- // void _setLocationOption() {
- // if (null != _locationPlugin) {
- // AMapLocationOption locationOption = new AMapLocationOption();
- //
- // ///是否单次定位
- // locationOption.onceLocation = false;
- // ///是否需要返回逆地理信息
- // locationOption.needAddress = true;
- // ///逆地理信息的语言类型
- // locationOption.geoLanguage = GeoLanguage.DEFAULT;
- //
- // ///设置Android端连续定位的定位间隔
- // locationOption.locationInterval = 20000;
- // ///设置Android端的定位模式<br>
- // ///可选值:<br>
- // ///<li>[AMapLocationMode.Battery_Saving]</li>
- // ///<li>[AMapLocationMode.Device_Sensors]</li>
- // ///<li>[AMapLocationMode.Hight_Accuracy]</li>
- // locationOption.locationMode = AMapLocationMode.Hight_Accuracy;
- //
- // ///设置iOS端的定位最小更新距离<br>
- // locationOption.distanceFilter = -1;
- // ///设置iOS端期望的定位精度
- // /// 可选值:<br>
- // /// <li>[DesiredAccuracy.Best] 最高精度</li>
- // /// <li>[DesiredAccuracy.BestForNavigation] 适用于导航场景的高精度 </li>
- // /// <li>[DesiredAccuracy.NearestTenMeters] 10米 </li>
- // /// <li>[DesiredAccuracy.Kilometer] 1000米</li>
- // /// <li>[DesiredAccuracy.ThreeKilometers] 3000米</li>
- // locationOption.desiredAccuracy = DesiredAccuracy.NearestTenMeters;
- // ///设置iOS端是否允许系统暂停定位
- // locationOption.pausesLocationUpdatesAutomatically = false;
- //
- // ///将定位参数设置给定位插件
- // _locationPlugin.setLocationOption(locationOption);
- // }
- // }
- @override
- Widget build(BuildContext context) {
- return OKToast(
- child: p.ChangeNotifierProvider<ThemeProvider>(
- create: (_) => ThemeProvider(),
- child: p.Consumer<ThemeProvider>(
- builder: (_, provider, __) {
- return MaterialApp(
- title: '电梯管家',
- //showPerformanceOverlay: true, //显示性能标签
- //debugShowCheckedModeBanner: false,
- //checkerboardRasterCacheImages: true,
- theme: provider.getTheme(),
- darkTheme: provider.getTheme(isDarkMode: true),
- home: widget.home ?? SplashPage(),
- 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);
- }
- }
|