初始化逻辑优化

hmxc
小赖 4 years ago
parent 655ed0f2f1
commit fe550f3494

@ -1,16 +1,11 @@
import 'package:akuCommunity/constants/config.dart'; import 'package:akuCommunity/main_initialize.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluwx/fluwx.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:akuCommunity/constants/app_theme.dart'; import 'package:akuCommunity/constants/app_theme.dart';
@ -22,47 +17,15 @@ import 'package:akuCommunity/utils/developer_util.dart';
import 'package:akuCommunity/utils/headers.dart'; import 'package:akuCommunity/utils/headers.dart';
void main() async { void main() async {
DeveloperUtil.setDev(true);
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
Future.delayed(Duration(seconds: 5), () {
FirebaseCrashlytics.instance.log("Higgs-Boson detected! Bailing out");
});
FlutterError.onError = (detail) { ///firebase crashlytics initalize
FirebaseCrashlytics.instance.recordFlutterError(detail); await MainInitialize.initFirebase();
}; MainInitialize.initTheme();
SystemChrome.setSystemUIOverlayStyle( await MainInitialize.initJPush();
SystemUiOverlayStyle( MainInitialize.initWechat();
statusBarColor: Colors.transparent,
systemNavigationBarColor: Colors.white,
),
);
JPush jpush = new JPush();
jpush.addEventHandler(
//
onReceiveNotification: (Map<String, dynamic> message) async {
print("flutter onReceiveNotification: $message");
},
//
onOpenNotification: (Map<String, dynamic> message) async {
print("flutter onOpenNotification: $message");
},
//
onReceiveMessage: (Map<String, dynamic> message) async {
print("flutter onReceiveMessage: $message");
},
);
jpush.setup(
appKey: "6a2c6507e3e8b3187ac1c9f9",
channel: "developer-default",
production: false,
debug: true, // debug
);
jpush.applyPushAuthority(
new NotificationSettingsIOS(sound: true, alert: true, badge: true));
DeveloperUtil.setDev(true);
registerWxApi(appId: AppConfig.wechatAppId);
runApp(MyApp()); runApp(MyApp());
} }

@ -0,0 +1,54 @@
import 'package:akuCommunity/constants/app_theme.dart';
import 'package:akuCommunity/constants/config.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluwx/fluwx.dart';
import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:power_logger/power_logger.dart';
class MainInitialize {
///firebase
static Future initFirebase() async {
await Firebase.initializeApp();
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
FlutterError.onError = (detail) {
FirebaseCrashlytics.instance.recordFlutterError(detail);
};
}
static initTheme() {
SystemChrome.setSystemUIOverlayStyle(SystemStyle.initial);
}
static Future initJPush() async {
JPush jpush = new JPush();
Function(Map<String, dynamic> message) jPushLogger(String type) {
return (Map<String, dynamic> message) async {
LoggerData.addData({
'type': type,
'message': message,
});
};
}
jpush.addEventHandler(
onReceiveNotification: jPushLogger('onReceiveNotification'),
onOpenNotification: jPushLogger('onOpenNotification'),
onReceiveMessage: jPushLogger('onReceiveMessage'),
);
jpush.setup(
appKey: "6a2c6507e3e8b3187ac1c9f9",
channel: "developer-default",
production: false,
debug: true,
);
String rID = await jpush.getRegistrationID();
LoggerData.addData('RegistrationID:$rID');
}
static initWechat() {
registerWxApi(appId: AppConfig.wechatAppId);
}
}

@ -114,7 +114,7 @@ class _SettingsPageState extends State<SettingsPage> {
// ), // ),
// ), // ),
_buildTile( _buildTile(
title: null, title: '关于小蜜蜂智慧社区',
onTap: () => Get.to(() => AboutPage()), onTap: () => Get.to(() => AboutPage()),
), ),
//TODO //TODO

@ -1,6 +1,5 @@
import 'dart:io'; import 'dart:io';
import 'package:akuCommunity/constants/app_theme.dart';
import 'package:akuCommunity/widget/picker/bee_house_picker.dart'; import 'package:akuCommunity/widget/picker/bee_house_picker.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';

Loading…
Cancel
Save