133 lines
4.5 KiB
Dart
133 lines
4.5 KiB
Dart
import 'dart:async';
|
||
import 'dart:io';
|
||
|
||
import 'package:aiplot/network/NetworkConfig.dart';
|
||
import 'package:aiplot/tools/home/home_page.dart';
|
||
import 'package:aiplot/tools/me/about_page.dart';
|
||
import 'package:aiplot/tools/me/feedback_page.dart';
|
||
import 'package:aiplot/tools/me/setting_page.dart';
|
||
import 'package:aiplot/tools/message/message_page.dart';
|
||
import 'package:aiplot/tools/shop/shop_page.dart';
|
||
import 'package:aiplot/tools/start_page.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||
import 'package:ironsource_mediation/ironsource_mediation.dart';
|
||
import 'package:sensors_analytics_flutter_plugin/sensors_analytics_flutter_plugin.dart';
|
||
|
||
import 'common/Global.dart';
|
||
import 'common/my_navigator_observers.dart';
|
||
import 'generated/l10n.dart';
|
||
|
||
Future<void> main() async {
|
||
await runZonedGuarded(() async {
|
||
WidgetsFlutterBinding.ensureInitialized();
|
||
Global.initialize().then((e) {
|
||
new Global();
|
||
runApp(CloudApp());
|
||
if (Platform.isAndroid) {
|
||
// 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后,是为了在渲染后进行set赋值,覆盖状态栏,写在渲染之前MaterialApp组件会覆盖掉这个值。
|
||
SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(statusBarColor: Colors.transparent);
|
||
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
|
||
}
|
||
});
|
||
}, (error, stackTrace) {});
|
||
}
|
||
|
||
class CloudApp extends StatefulWidget {
|
||
@override
|
||
_CloudAppState createState() => _CloudAppState();
|
||
}
|
||
|
||
class _CloudAppState extends State<CloudApp> with IronSourceInitializationListener {
|
||
// 注册方法,等待被原生通过invokeMethod唤起 接收原生数据
|
||
Future<dynamic> nativeCallHandler(MethodCall methodCall) async {
|
||
switch (methodCall.method) {
|
||
case "AreaCode": //时区选择
|
||
|
||
final AreaCode = await methodCall.arguments["AreaCode"];
|
||
final AreaName = await methodCall.arguments["AreaName"];
|
||
// EventBusUtil.fire(LoginAreaCodeEvent(AreaCode, AreaName));
|
||
break;
|
||
}
|
||
}
|
||
|
||
@override
|
||
void initState() {
|
||
Global.method.setMethodCallHandler(nativeCallHandler);
|
||
|
||
//神策初始化
|
||
SensorsAnalyticsFlutterPlugin.init(
|
||
serverUrl: "https://sj.datasink.sensorsdata.cn/sa?project=production&token=8749cbadc8e370e7",
|
||
autoTrackTypes: <SAAutoTrackType>{
|
||
SAAutoTrackType.APP_START,
|
||
SAAutoTrackType.APP_VIEW_SCREEN,
|
||
SAAutoTrackType.APP_CLICK,
|
||
SAAutoTrackType.APP_END
|
||
},
|
||
enableLog: false,
|
||
visualized: VisualizedConfig(autoTrack: true, properties: true),
|
||
android: AndroidConfig(maxCacheSize: 32 * 1024 * 1024, jellybean: true, subProcessFlush: true),
|
||
ios: IOSConfig(maxCacheSize: 10000));
|
||
|
||
// 公共属性
|
||
SensorsAnalyticsFlutterPlugin.registerSuperProperties({
|
||
"S_Key_system_APPnames": "HissAi",
|
||
"Platform_type": Platform.isAndroid ? "Android" : "iOS",
|
||
"AppId": NetworkConfig.AppId,
|
||
});
|
||
|
||
//is广告初始化
|
||
IronSource.setFlutterVersion("3.3.1");
|
||
IronSource.init(appKey: "19ff4f345");
|
||
|
||
super.initState();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return MaterialApp(
|
||
navigatorObservers: [MyNavigatorObserver()],
|
||
title: 'AI',
|
||
localizationsDelegates: const [
|
||
GlobalMaterialLocalizations.delegate,
|
||
GlobalWidgetsLocalizations.delegate,
|
||
GlobalCupertinoLocalizations.delegate,
|
||
S.delegate
|
||
],
|
||
supportedLocales: const [
|
||
Locale("en"),
|
||
Locale("zh"),
|
||
Locale("ja"),
|
||
],
|
||
|
||
home: StartPage(),
|
||
|
||
//注册路由
|
||
routes: <String, WidgetBuilder>{
|
||
'/HomePage': (BuildContext context) => HomePage(),
|
||
'/SettingPage': (BuildContext context) => SettingPage(),
|
||
'/ShopPage': (BuildContext context) => ShopPage(),
|
||
'/AboutPage': (BuildContext context) => AboutPage(),
|
||
'/MessagePage': (BuildContext context) => MessagePage(),
|
||
'/FeedbackPage': (BuildContext context) => FeedbackPage(),
|
||
},
|
||
|
||
debugShowMaterialGrid: false,
|
||
//显示网格
|
||
debugShowCheckedModeBanner: false,
|
||
//去掉右上角的debug
|
||
builder: EasyLoading.init(),
|
||
);
|
||
}
|
||
|
||
@override
|
||
void onInitializationComplete() {
|
||
// TODO: implement onInitializationComplete
|
||
//is sdk 初始化完成
|
||
debugPrint("ironSource SDK is initialized");
|
||
print("ironSource SDK is initialized");
|
||
}
|
||
}
|