|
|
@@ -1,5 +1,6 @@ |
|
|
|
import 'dart:async'; |
|
|
|
import 'dart:convert' as convert; |
|
|
|
import 'dart:io'; |
|
|
|
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart'; |
|
|
|
import 'package:flutter/cupertino.dart'; |
|
|
@@ -13,6 +14,7 @@ import 'package:provider/provider.dart'; |
|
|
|
import 'package:zhiying_base_widget/dialog/global_dialog/advertising_dialog/advertising_dialog.dart'; |
|
|
|
import 'package:zhiying_base_widget/dialog/global_dialog/intellect_search_goods_dialog/intellect_create.dart'; |
|
|
|
import 'package:zhiying_base_widget/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart'; |
|
|
|
import 'package:zhiying_base_widget/dialog/notification_dialog/notification_dialog.dart'; |
|
|
|
import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart'; |
|
|
|
import 'package:zhiying_base_widget/models/app_config_model.dart'; |
|
|
|
import 'package:zhiying_base_widget/pages/custom_page/event/reload_event.dart'; |
|
|
@@ -58,7 +60,6 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
|
StreamSubscription streamSubscription; |
|
|
|
|
|
|
|
StreamSubscription reloadSubscription; |
|
|
|
StreamSubscription aliasSubscription; |
|
|
|
StreamSubscription logOutSubscription; |
|
|
|
StreamSubscription loginSubscription; |
|
|
|
|
|
|
@@ -111,6 +112,9 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
|
|
|
|
|
Moblink.uploadPrivacyPermissionStatus(1, (bool success) {}); |
|
|
|
SharesdkPlugin.uploadPrivacyPermissionStatus(1, (bool success) {}); |
|
|
|
|
|
|
|
///设置推送标识 |
|
|
|
setAlias(); |
|
|
|
// 是安卓系统,Android场景还原的实现 |
|
|
|
/*if (defaultTargetPlatform == TargetPlatform.android) { |
|
|
|
|
|
|
@@ -121,30 +125,14 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
|
// 监听开始(传递监听到原生端,用户监听场景还原的数据回传回来) |
|
|
|
eventChannelSubscription = _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); |
|
|
|
|
|
|
|
MobPushUtil.addPushReceiver(); |
|
|
|
aliasSubscription = EventUtil.instance.on<LoginSuccessEvent>().listen((event) async { |
|
|
|
UserInfoModel userInfo = UserInfoNotifier?.staitcUserInfo; |
|
|
|
var setting = await NativeUtil.getSetting(); |
|
|
|
String masterId = setting['master_id']; |
|
|
|
Logger.log("我的Alias: " + masterId + "_" + userInfo?.userId); |
|
|
|
if (!EmptyUtil.isEmpty(userInfo.userId) && !EmptyUtil.isEmpty(masterId)) { |
|
|
|
MobPushUtil.setAlias(masterId + "_" + userInfo.userId); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
logOutSubscription = EventUtil.instance.on<LogOut>().listen((event) { |
|
|
|
MobPushUtil.deleteAlias(); |
|
|
|
SharedPreferencesUtil.setStringValue(Constants.isSetTag, "0"); |
|
|
|
}); |
|
|
|
|
|
|
|
MobPushUtil.addPushReceiver(); |
|
|
|
loginSubscription = EventUtil.instance.on<LoginSuccessEvent>().listen((event) async { |
|
|
|
UserInfoModel userInfo = UserInfoNotifier?.staitcUserInfo; |
|
|
|
var setting = await NativeUtil.getSetting(); |
|
|
|
String masterId = setting['master_id']; |
|
|
|
Logger.log("我的Alias: " + masterId + "_" + userInfo?.userId); |
|
|
|
if (!EmptyUtil.isEmpty(userInfo.userId) && !EmptyUtil.isEmpty(masterId)) { |
|
|
|
MobPushUtil.setAlias(masterId + "_" + userInfo.userId); |
|
|
|
} |
|
|
|
setAlias(); |
|
|
|
}); |
|
|
|
} catch (e, s) { |
|
|
|
print(e); |
|
|
@@ -170,7 +158,6 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
|
WidgetsBinding.instance.removeObserver(this); |
|
|
|
streamSubscription.cancel(); |
|
|
|
reloadSubscription?.cancel(); |
|
|
|
aliasSubscription?.cancel(); |
|
|
|
logOutSubscription?.cancel(); |
|
|
|
loginSubscription?.cancel(); |
|
|
|
eventChannelSubscription?.cancel(); |
|
|
@@ -362,12 +349,36 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
|
String showNotiPermissionTime = await SharedPreferencesUtil.getStringValue(Constants.showNotiPermissionTime, defaultVal: "5"); |
|
|
|
int timer = int.tryParse(showNotiPermissionTime) ?? 0; |
|
|
|
if (timer % 5 == 0) { |
|
|
|
if (!await Permission.notification.isGranted || !await Permission.storage.isGranted) { |
|
|
|
timer++; |
|
|
|
SharedPreferencesUtil.setStringValue(Constants.showNotiPermissionTime, timer.toString()); |
|
|
|
if (!await Permission.storage.isGranted) { |
|
|
|
await NotificationSettingDialogNew.show(context); |
|
|
|
} |
|
|
|
String notificationAgree = await SharedPreferencesUtil.getStringValue(Constants.notificationAgree, defaultVal: "0"); |
|
|
|
|
|
|
|
if (notificationAgree == "1" && await Permission.notification.isGranted) { |
|
|
|
///啥也不干 |
|
|
|
} else { |
|
|
|
if (notificationAgree == "0" || !await Permission.notification.isGranted) { |
|
|
|
bool isGranted = await Permission.notification.isGranted; |
|
|
|
var result = await showDialog( |
|
|
|
context: context, |
|
|
|
child: NotificationDialog( |
|
|
|
isGranted: isGranted, |
|
|
|
)); |
|
|
|
if (result != null && result) { |
|
|
|
SharedPreferencesUtil.setStringValue(Constants.notificationAgree, "1"); |
|
|
|
if (!await Permission.notification.isGranted) { |
|
|
|
if (Platform.isIOS) { |
|
|
|
openAppSettings(); |
|
|
|
} else { |
|
|
|
await NativeUtil.openAppSettings(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
timer++; |
|
|
|
SharedPreferencesUtil.setStringValue(Constants.showNotiPermissionTime, timer.toString()); |
|
|
|
|
|
|
|
// 活动弹窗 |
|
|
|
await AdvertisingDialog.show(context); |
|
|
@@ -458,4 +469,21 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
|
@override |
|
|
|
// TODO: implement wantKeepAlive |
|
|
|
bool get wantKeepAlive => true; |
|
|
|
|
|
|
|
///设置定向推送 |
|
|
|
void setAlias() async { |
|
|
|
///如果没有开启通知则设置别名 |
|
|
|
if (await SharedPreferencesUtil.getStringValue(Constants.notificationAgree, defaultVal: "0") == "1") { |
|
|
|
UserInfoModel userInfo = UserInfoNotifier?.staitcUserInfo; |
|
|
|
var setting = await NativeUtil.getSetting(); |
|
|
|
String masterId = setting['master_id']; |
|
|
|
Logger.log("我的Alias: " + masterId + "_" + userInfo?.userId); |
|
|
|
if (!EmptyUtil.isEmpty(userInfo.userId) && !EmptyUtil.isEmpty(masterId)) { |
|
|
|
print("设置标签" + masterId + "_" + userInfo.userId); |
|
|
|
await MobPushUtil.restartPush(); |
|
|
|
await MobPushUtil.setAlias(masterId + "_" + userInfo.userId); |
|
|
|
SharedPreferencesUtil.setStringValue(Constants.isSetTag, "1"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |