autosos_flutter/lib/main.dart

198 lines
6.0 KiB
Dart
Raw Normal View History

2024-03-12 20:31:03 +08:00
import 'dart:io';
2024-03-09 17:13:48 +08:00
import 'package:autosos_flutter/config/theme_colors.dart';
2024-03-07 18:00:47 +08:00
import 'package:autosos_flutter/pages/login/login_page.dart';
2024-03-12 20:31:03 +08:00
import 'package:autosos_flutter/util/sp_util.dart';
2024-02-18 22:12:08 +08:00
import 'package:flutter/material.dart';
2024-03-12 20:31:03 +08:00
import 'package:flutter/services.dart';
2024-03-09 14:28:23 +08:00
import 'package:flutter_easyloading/flutter_easyloading.dart';
2024-03-12 20:31:03 +08:00
import 'package:getuiflut/getuiflut.dart';
2024-03-09 17:13:48 +08:00
import 'package:shared_preferences/shared_preferences.dart';
2024-02-18 22:12:08 +08:00
2024-03-12 20:31:03 +08:00
import 'config/getui_constant.dart';
2024-02-18 22:12:08 +08:00
void main() {
2024-03-09 17:13:48 +08:00
SharedPreferences.setMockInitialValues({});
2024-02-18 22:12:08 +08:00
runApp(const MyApp());
}
2024-03-12 20:31:03 +08:00
class MyApp extends StatefulWidget {
2024-02-18 22:12:08 +08:00
const MyApp({super.key});
2024-03-12 20:31:03 +08:00
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
2024-02-18 22:12:08 +08:00
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
2024-03-09 14:28:23 +08:00
title: 'Flutter Demo',
theme: ThemeData(
2024-03-09 17:13:48 +08:00
colorScheme: ColorScheme.fromSeed(seedColor: ThemeColors.primary),
2024-03-09 14:28:23 +08:00
useMaterial3: true,
),
home: const LoginPage(),
builder: EasyLoading.init(),
);
2024-02-18 22:12:08 +08:00
}
2024-03-12 20:31:03 +08:00
String _platformVersion = 'Unknown';
String _payloadInfo = 'Null';
String _userMsg = "";
String _notificationState = "";
String _getClientId = "";
String _getDeviceToken = "";
String _onReceivePayload = "";
String _onReceiveNotificationResponse = "";
String _onAppLinkPayLoad = "";
SPUtil spUtil = SPUtil();
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
String payloadInfo = "default";
String notificationState = "default";
// Platform messages may fail, so we use a try/catch PlatformException.
if (Platform.isIOS) {
getSdkVersion();
Getuiflut().startSdk(
appId: GetuiConstant.appId,
appKey: GetuiConstant.appKey,
appSecret: GetuiConstant.appSecret);
}
try {
platformVersion = await Getuiflut.platformVersion;
print('platformVersion' + platformVersion);
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
_payloadInfo = payloadInfo;
_notificationState = notificationState;
});
Getuiflut().addEventHandler(onReceiveClientId: (String message) async {
print("flutter onReceiveClientId: $message");
spUtil.setString("clientId", message);
setState(() {
_getClientId = "ClientId: $message";
});
}, onReceiveMessageData: (Map<String, dynamic> msg) async {
print("flutter onReceiveMessageData: $msg");
setState(() {
_payloadInfo = msg['payload'];
});
}, onNotificationMessageArrived: (Map<String, dynamic> msg) async {
print("flutter onNotificationMessageArrived: $msg");
setState(() {
_notificationState = 'Arrived';
});
}, onNotificationMessageClicked: (Map<String, dynamic> msg) async {
print("flutter onNotificationMessageClicked: $msg");
setState(() {
_notificationState = 'Clicked';
});
}, onTransmitUserMessageReceive: (Map<String, dynamic> msg) async {
print("flutter onTransmitUserMessageReceive:$msg");
setState(() {
_userMsg = msg["msg"];
});
}, onRegisterDeviceToken: (String message) async {
print("flutter onRegisterDeviceToken: $message");
setState(() {
_getDeviceToken = "$message";
});
}, onReceivePayload: (Map<String, dynamic> message) async {
print("flutter onReceivePayload: $message");
setState(() {
_onReceivePayload = "$message";
});
}, onReceiveNotificationResponse: (Map<String, dynamic> message) async {
print("flutter onReceiveNotificationResponse: $message");
setState(() {
_onReceiveNotificationResponse = "$message";
});
}, onAppLinkPayload: (String message) async {
print("flutter onAppLinkPayload: $message");
setState(() {
_onAppLinkPayLoad = "$message";
});
}, onPushModeResult: (Map<String, dynamic> message) async {
print("flutter onPushModeResult: $message");
}, onSetTagResult: (Map<String, dynamic> message) async {
print("flutter onSetTagResult: $message");
}, onAliasResult: (Map<String, dynamic> message) async {
print("flutter onAliasResult: $message");
}, onQueryTagResult: (Map<String, dynamic> message) async {
print("flutter onQueryTagResult: $message");
}, onWillPresentNotification: (Map<String, dynamic> message) async {
print("flutter onWillPresentNotification: $message");
}, onOpenSettingsForNotification: (Map<String, dynamic> message) async {
print("flutter onOpenSettingsForNotification: $message");
}, onGrantAuthorization: (String granted) async {
print("flutter onGrantAuthorization: $granted");
}, onLiveActivityResult: (Map<String, dynamic> message) async {
print("flutter onLiveActivityResult: $message");
});
}
Future<void> initGetuiSdk() async {
try {
Getuiflut.initGetuiSdk;
} catch (e) {
e.toString();
}
}
Future<void> getClientId() async {
String getClientId;
try {
getClientId = await Getuiflut.getClientId;
print(getClientId);
} catch (e) {
print(e.toString());
}
}
Future<void> getSdkVersion() async {
String ver;
try {
ver = await Getuiflut.sdkVersion;
print(ver);
} catch (e) {
print(e.toString());
}
}
Future<void> getLaunchNotification() async {
Map info;
try {
info = await Getuiflut.getLaunchNotification;
print(info);
} catch (e) {
print(e.toString());
}
}
2024-02-18 22:12:08 +08:00
}