推送相关 和确认协议
This commit is contained in:
parent
153a2f07cc
commit
9f3972a8de
@ -71,6 +71,8 @@
|
|||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
|
android:showWhenLocked="true"
|
||||||
|
android:turnScreenOn="true"
|
||||||
android:networkSecurityConfig="@xml/network_security_config"
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||||
|
|||||||
@ -275,7 +275,7 @@ class InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClien
|
|||||||
return Container(
|
return Container(
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
left: 12.sp, right: 12.sp),
|
left: 12.sp, right: 12.sp),
|
||||||
height:urlList.length==0?47.sp: 108.sp,
|
height:urlList.length==0?47.sp: 118.sp,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
image: DecorationImage(
|
image: DecorationImage(
|
||||||
fit: BoxFit.fill,
|
fit: BoxFit.fill,
|
||||||
|
|||||||
198
circle_app/lib/app/dialog/YesAgreementDialog.dart
Normal file
198
circle_app/lib/app/dialog/YesAgreementDialog.dart
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/gestures.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:tencent_chat_push_for_china/tencent_chat_push_for_china.dart';
|
||||||
|
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
|
||||||
|
|
||||||
|
import '../../common/values/pushconfig.dart';
|
||||||
|
import '../../util/SharedPreferencesHelper.dart';
|
||||||
|
import '../../util/device.dart';
|
||||||
|
import '../../util/util.dart';
|
||||||
|
|
||||||
|
class YesAgreementDialog extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_CustomDialogState createState() => _CustomDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
double myProgress = 0;
|
||||||
|
|
||||||
|
class _CustomDialogState extends State<YesAgreementDialog> {
|
||||||
|
bool isDownload = false;
|
||||||
|
|
||||||
|
void incrementCounter() {}
|
||||||
|
|
||||||
|
void setDownloadUi() {
|
||||||
|
setState(() {
|
||||||
|
isDownload = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return WillPopScope(
|
||||||
|
onWillPop: () async {
|
||||||
|
|
||||||
|
print(getAgreemement());
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
child: Dialog(
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
child: Container(
|
||||||
|
height: 277.sp,
|
||||||
|
padding: const EdgeInsets.all(1.0),
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.rectangle,
|
||||||
|
borderRadius: BorderRadius.circular(10.0),
|
||||||
|
gradient: const LinearGradient(
|
||||||
|
colors: [Color(0xFFDD3DF4), Color(0xFF30FFD9)],
|
||||||
|
begin: Alignment.topCenter,
|
||||||
|
end: Alignment.bottomCenter,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
margin: EdgeInsets.all(1.sp),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.rectangle,
|
||||||
|
borderRadius: BorderRadius.circular(10.0),
|
||||||
|
gradient: const LinearGradient(
|
||||||
|
colors: [Color(0xFF4C3E5F), Color(0xFF324140)],
|
||||||
|
begin: Alignment.topCenter,
|
||||||
|
end: Alignment.bottomCenter,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
margin: EdgeInsets.only(left: 10.sp, right: 10.sp),
|
||||||
|
child: RichText(
|
||||||
|
text: TextSpan(
|
||||||
|
text: "感谢您信任并使用跨友APP,在你使用跨友的服务之前,请认真阅读",
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 14.sp,
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
TextSpan(
|
||||||
|
text: "《用户协议》",
|
||||||
|
style: TextStyle(
|
||||||
|
color: Color(0xFF21BEAB),
|
||||||
|
),
|
||||||
|
recognizer: TapGestureRecognizer()
|
||||||
|
..onTap = () {
|
||||||
|
navigateToUserAgreement();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextSpan(
|
||||||
|
text: "和",
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextSpan(
|
||||||
|
text: "《隐私政策》",
|
||||||
|
style: TextStyle(
|
||||||
|
color: Color(0xFF21BEAB),
|
||||||
|
),
|
||||||
|
recognizer: TapGestureRecognizer()
|
||||||
|
..onTap = () {
|
||||||
|
navigateToPrivacyPolicy();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextSpan(
|
||||||
|
text:
|
||||||
|
"的全部内容,以了解用户权力义务和个人信息处理规则。跨友仅会将您的信息用于提供服务和改善体验,我们将权力保障您的信息安全,请同意后使用,若您不同意本隐私政策,很遗憾,我们将无法为您提供完整的产品和服务。",
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 14.sp,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 10.sp),
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () async {
|
||||||
|
// 点击操作
|
||||||
|
var sp = await SharedPreferencesHelper.getInstance();
|
||||||
|
sp.setBool(SharedPreferencesHelper.AGREEMENT, true);
|
||||||
|
pushLoginPage();
|
||||||
|
uploadBuzIDAndToken();
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
width: 240.sp,
|
||||||
|
padding: EdgeInsets.symmetric(
|
||||||
|
vertical: 10,
|
||||||
|
horizontal: 44,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
gradient: LinearGradient(
|
||||||
|
colors: [Color(0xFFDD3DF4), Color(0xFF30FFD9)],
|
||||||
|
begin: Alignment.centerLeft,
|
||||||
|
end: Alignment.centerRight,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(30),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
"同意并继续使用",
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 16.sp,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
// 点击不同意按钮的操作
|
||||||
|
exit(1);
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
"不同意并退出应用",
|
||||||
|
style: TextStyle(
|
||||||
|
color: Color(0xFFB8C2CC),
|
||||||
|
fontSize: 16.sp,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void uploadBuzIDAndToken() async {
|
||||||
|
final CoreServicesImpl coreInstance = TIMUIKitCore.getInstance();
|
||||||
|
await ChannelPush.init((msg) {});
|
||||||
|
|
||||||
|
int? businessID = await TimUiKitPushPlugin.getBuzId(PushConfig.appInfo);
|
||||||
|
|
||||||
|
String token = await ChannelPush.getDeviceToken();
|
||||||
|
ChannelPush.uploadToken();
|
||||||
|
|
||||||
|
print("token=" + token);
|
||||||
|
if (token != "") {
|
||||||
|
V2TimCallback res = await coreInstance.setOfflinePushConfig(
|
||||||
|
token: token, businessID: businessID);
|
||||||
|
|
||||||
|
print("token=" + res.code.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -31,9 +31,7 @@ class LoginLogic extends GetxController {
|
|||||||
// TODO: implement onInit
|
// TODO: implement onInit
|
||||||
super.onInit();
|
super.onInit();
|
||||||
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
|
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
|
||||||
String loginPhone =
|
String loginPhone = await sharedPreferences.getString(SharedPreferencesHelper.LOGINPHONE) ?? "";
|
||||||
await sharedPreferences.getString(SharedPreferencesHelper.LOGINPHONE) ??
|
|
||||||
"";
|
|
||||||
print(loginPhone);
|
print(loginPhone);
|
||||||
phoneEditingController.text = loginPhone;
|
phoneEditingController.text = loginPhone;
|
||||||
if (GetUtils.isPhoneNumber(loginPhone) && loginPhone.length == 11) {
|
if (GetUtils.isPhoneNumber(loginPhone) && loginPhone.length == 11) {
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
import '../../router/app_routers.dart';
|
import '../../router/app_routers.dart';
|
||||||
import '../../util/SharedPreferencesHelper.dart';
|
import '../../util/SharedPreferencesHelper.dart';
|
||||||
|
import '../dialog/YesAgreementDialog.dart';
|
||||||
import 'state.dart';
|
import 'state.dart';
|
||||||
|
|
||||||
import '../../network/api.dart';
|
import '../../network/api.dart';
|
||||||
@ -27,7 +32,19 @@ class SplashLogic extends GetxController {
|
|||||||
super.onInit();
|
super.onInit();
|
||||||
// await Future.delayed(Duration(seconds: 30));
|
// await Future.delayed(Duration(seconds: 30));
|
||||||
if ((await getAuthorization()).isEmpty) {
|
if ((await getAuthorization()).isEmpty) {
|
||||||
|
if(Platform.isIOS){
|
||||||
pushLoginPage();
|
pushLoginPage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool isAgreemement = await getAgreemement();
|
||||||
|
if(!isAgreemement){
|
||||||
|
showReportDialog();
|
||||||
|
}else{
|
||||||
|
pushLoginPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var data =
|
var data =
|
||||||
await DioManager.instance.put(url: Api.refreshToken, params: {});
|
await DioManager.instance.put(url: Api.refreshToken, params: {});
|
||||||
@ -63,4 +80,15 @@ class SplashLogic extends GetxController {
|
|||||||
// Get.toNamed(AppRoutes.Home);
|
// Get.toNamed(AppRoutes.Home);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void showReportDialog() {
|
||||||
|
FlutterNativeSplash.remove();
|
||||||
|
showDialog(
|
||||||
|
context: Get.context!,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return YesAgreementDialog();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,6 +103,7 @@ class UserinfoLogic extends GetxController {
|
|||||||
userInfoBean = bean.data.user;
|
userInfoBean = bean.data.user;
|
||||||
isVip = userInfoBean?.vip ?? 0;
|
isVip = userInfoBean?.vip ?? 0;
|
||||||
imId = bean.data.accountId;
|
imId = bean.data.accountId;
|
||||||
|
print("imId="+imId);
|
||||||
if (isMe) {
|
if (isMe) {
|
||||||
isOnline = true;
|
isOnline = true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import 'package:circle_app/main.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
|
||||||
|
|
||||||
import '../../components/my_app_bar.dart';
|
import '../../components/my_app_bar.dart';
|
||||||
import '../../router/app_routers.dart';
|
import '../../router/app_routers.dart';
|
||||||
@ -656,7 +657,15 @@ class MyTabbedScreenState extends State<UserinfoPage>
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
sendmsg(){
|
||||||
|
OfflinePushInfo(
|
||||||
|
title : '测试', // 推送通知标题。留空字符串时,按照优先级,IM后台自动替换成 sender的昵称 => sender ID。因此,如无特殊需求,该字段建议留空,可达到和微信一致的效果
|
||||||
|
desc : '测试', // 推送第二行小字部分
|
||||||
|
disablePush : false,
|
||||||
|
ext : 'null', // 推送内额外信息,对方可于单击通知跳转时拿到。建议传含Conversation信息的JSON,用于收件方跳转至对应Chat。可参见下方TUIKit的实例代码。
|
||||||
|
androidOPPOChannelID : 'new_message', // OPPO的channel ID
|
||||||
|
);
|
||||||
|
}
|
||||||
Widget _buildAvatar1(UserinfoLogic controller) {
|
Widget _buildAvatar1(UserinfoLogic controller) {
|
||||||
if (controller.userInfoBean == null) {
|
if (controller.userInfoBean == null) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
|
|||||||
@ -35,7 +35,9 @@ class PushConfig{
|
|||||||
static const String OPPOPushAPPSECRET = "7d17a5b2b2fc43eda61005807002f654";
|
static const String OPPOPushAPPSECRET = "7d17a5b2b2fc43eda61005807002f654";
|
||||||
static const String OPPOPushAPPID = "31286141";
|
static const String OPPOPushAPPID = "31286141";
|
||||||
static const String OPPOChannelID = "new_message";
|
static const String OPPOChannelID = "new_message";
|
||||||
|
//appsecret:7d17a5b2b2fc43eda61005807002f654
|
||||||
|
//appserversecret:07a4d3b9f3f249d2954866706af000d9
|
||||||
|
//07a4d3b9f3f249d2954866706af000d9
|
||||||
|
|
||||||
// Business ID for Apple APNS 正式环境39381 测试环境39382
|
// Business ID for Apple APNS 正式环境39381 测试环境39382
|
||||||
static const ApplePushBuzID = 39381;
|
static const ApplePushBuzID = 39381;
|
||||||
@ -73,8 +75,8 @@ class ChannelPush{
|
|||||||
|
|
||||||
// create new notification channel
|
// create new notification channel
|
||||||
cPush.createNotificationChannel(
|
cPush.createNotificationChannel(
|
||||||
channelId: "new_message",
|
channelId: PushConfig.OPPOChannelID,
|
||||||
channelName: "chat_message",
|
channelName: "消息推送",
|
||||||
channelDescription:
|
channelDescription:
|
||||||
"The notification for chat message from Tencent Cloud IM"
|
"The notification for chat message from Tencent Cloud IM"
|
||||||
);
|
);
|
||||||
@ -89,9 +91,6 @@ class ChannelPush{
|
|||||||
return cPush.getDevicePushToken();
|
return cPush.getDevicePushToken();
|
||||||
}
|
}
|
||||||
static Future<bool> uploadToken() async {
|
static Future<bool> uploadToken() async {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return await cPush.uploadToken(PushConfig.appInfo);
|
return await cPush.uploadToken(PushConfig.appInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,11 +33,6 @@ final TUIChatSeparateViewModel chatSeparateViewModel =
|
|||||||
TUIChatSeparateViewModel();
|
TUIChatSeparateViewModel();
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// FlutterError.onError = (FlutterErrorDetails details) {
|
|
||||||
// FlutterError.dumpErrorToConsole(details);
|
|
||||||
// // if (kReleaseMode)
|
|
||||||
// // //处理线上错误,如统计上传
|
|
||||||
// };
|
|
||||||
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
|
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
|
||||||
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
|
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
@ -64,29 +59,28 @@ logoutIM() async {
|
|||||||
print(result.desc + '退出IM');
|
print(result.desc + '退出IM');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//获取设备Token,获取成功后开启离线推送
|
//获取设备Token,获取成功后开启离线推送
|
||||||
void uploadBuzIDAndToken() async {
|
void uploadBuzIDAndToken() async {
|
||||||
await ChannelPush.init((msg) { });
|
bool isAgreemement = await getAgreemement();
|
||||||
|
if(!isAgreemement){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await ChannelPush.init((msg) {});
|
||||||
|
|
||||||
int? businessID = await TimUiKitPushPlugin.getBuzId(PushConfig.appInfo);
|
int? businessID = await TimUiKitPushPlugin.getBuzId(PushConfig.appInfo);
|
||||||
|
|
||||||
String token = await ChannelPush.getDeviceToken();
|
String token = await ChannelPush.getDeviceToken();
|
||||||
ChannelPush.uploadToken();
|
ChannelPush.uploadToken();
|
||||||
|
|
||||||
print("token="+token);
|
print("token=" + token);
|
||||||
if (token != "") {
|
if (token != "") {
|
||||||
V2TimCallback res = await coreInstance.setOfflinePushConfig(
|
V2TimCallback res = await coreInstance.setOfflinePushConfig(
|
||||||
token: token,
|
token: token, businessID: businessID);
|
||||||
businessID: businessID
|
|
||||||
);
|
print("token=" + res.code.toString());
|
||||||
print("token="+res.code.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
initPush() {
|
initPush() {
|
||||||
// final TimUiKitPushPlugin cPush = TimUiKitPushPlugin(
|
// final TimUiKitPushPlugin cPush = TimUiKitPushPlugin(
|
||||||
// isUseGoogleFCM: true, // 中国大陆版无此参数
|
// isUseGoogleFCM: true, // 中国大陆版无此参数
|
||||||
@ -95,7 +89,6 @@ initPush() {
|
|||||||
// pushClickAction: pushClickAction, // 单击通知后的事件回调,会在STEP6讲解
|
// pushClickAction: pushClickAction, // 单击通知后的事件回调,会在STEP6讲解
|
||||||
// appInfo: PushConfig.appInfo, // 传入STEP1做的appInfo
|
// appInfo: PushConfig.appInfo, // 传入STEP1做的appInfo
|
||||||
// );
|
// );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//跳转发消息页面
|
//跳转发消息页面
|
||||||
@ -142,7 +135,7 @@ createCustomMsg(String userId, String imId) async {
|
|||||||
|
|
||||||
if (data['data']['both_cities'] != null) {
|
if (data['data']['both_cities'] != null) {
|
||||||
List city = data['data']['both_cities'];
|
List city = data['data']['both_cities'];
|
||||||
print('城市'+city.toString());
|
print('城市' + city.toString());
|
||||||
if (city.isNotEmpty) {
|
if (city.isNotEmpty) {
|
||||||
desc = '你们都在${city.first}留下过足迹';
|
desc = '你们都在${city.first}留下过足迹';
|
||||||
cityStr = '你们都在${city.first}留下过足迹';
|
cityStr = '你们都在${city.first}留下过足迹';
|
||||||
@ -231,7 +224,6 @@ sendCustomMsg(String userId, String data, String desc) async {
|
|||||||
// 发送自定义消息
|
// 发送自定义消息
|
||||||
//EventBusManager.fire(SendCoustomMessage(createCustomMessageRes));
|
//EventBusManager.fire(SendCoustomMessage(createCustomMessageRes));
|
||||||
|
|
||||||
|
|
||||||
// 在sendMessage时,若只填写receiver则发个人用户单聊消息
|
// 在sendMessage时,若只填写receiver则发个人用户单聊消息
|
||||||
// 若只填写groupID则发群组消息
|
// 若只填写groupID则发群组消息
|
||||||
// 若填写了receiver与groupID则发群内的个人用户,消息在群聊中显示,只有指定receiver能看见
|
// 若填写了receiver与groupID则发群内的个人用户,消息在群聊中显示,只有指定receiver能看见
|
||||||
@ -257,18 +249,21 @@ class MyApp extends StatefulWidget {
|
|||||||
|
|
||||||
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||||
AppLifecycleState? _lastLifecycleState;
|
AppLifecycleState? _lastLifecycleState;
|
||||||
|
|
||||||
// This widget is the root of your application.
|
// This widget is the root of your application.
|
||||||
|
|
||||||
final List<String> _guideList = ['bg', 'home_back'];
|
final List<String> _guideList = ['bg', 'home_back'];
|
||||||
@override
|
|
||||||
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
// WidgetsBinding.instance.removeObserver(this);
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
initIM();
|
initIM();
|
||||||
// WidgetsBinding.instance.addObserver(this);
|
WidgetsBinding.instance.addObserver(this);
|
||||||
if (Platform.isAndroid) {
|
if (Platform.isAndroid) {
|
||||||
initWxApi();
|
initWxApi();
|
||||||
}
|
}
|
||||||
@ -278,8 +273,9 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|||||||
super.initState();
|
super.initState();
|
||||||
addPayNotifi();
|
addPayNotifi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeAppLifecycleState(AppLifecycleState state) async{
|
void didChangeAppLifecycleState(AppLifecycleState state) async {
|
||||||
print("--" + state.toString());
|
print("--" + state.toString());
|
||||||
_lastLifecycleState = state;
|
_lastLifecycleState = state;
|
||||||
int? unreadCount = 0;
|
int? unreadCount = 0;
|
||||||
@ -290,35 +286,48 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|||||||
.getTotalUnreadMessageCount();
|
.getTotalUnreadMessageCount();
|
||||||
if (getTotalUnreadMessageCountRes.code == 0) {
|
if (getTotalUnreadMessageCountRes.code == 0) {
|
||||||
//拉取成功
|
//拉取成功
|
||||||
unreadCount = getTotalUnreadMessageCountRes.data;//会话未读总数
|
unreadCount = getTotalUnreadMessageCountRes.data; //会话未读总数
|
||||||
|
}
|
||||||
|
print("state=" + state.toString());
|
||||||
|
if (Platform.isIOS) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case AppLifecycleState.inactive:
|
case AppLifecycleState.inactive:
|
||||||
TencentImSDKPlugin.v2TIMManager
|
setOfflinePushStatus(
|
||||||
.getOfflinePushManager()
|
status: AppStatus.background, totalCount: unreadCount);
|
||||||
.doBackground(unreadCount: unreadCount ?? 0);
|
if (unreadCount != null) {
|
||||||
if(unreadCount != null){
|
|
||||||
|
|
||||||
ChannelPush.setBadgeNum(unreadCount);
|
ChannelPush.setBadgeNum(unreadCount);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AppLifecycleState.resumed:
|
case AppLifecycleState.resumed:
|
||||||
TencentImSDKPlugin.v2TIMManager
|
setOfflinePushStatus(status: AppStatus.foreground);
|
||||||
.getOfflinePushManager()
|
|
||||||
.doForeground();
|
|
||||||
break;
|
break;
|
||||||
case AppLifecycleState.paused:
|
case AppLifecycleState.paused:
|
||||||
TencentImSDKPlugin.v2TIMManager
|
setOfflinePushStatus(
|
||||||
.getOfflinePushManager()
|
status: AppStatus.background, totalCount: unreadCount);
|
||||||
.doBackground(unreadCount: unreadCount ?? 0);
|
if (unreadCount != null) {
|
||||||
if(unreadCount != null){
|
|
||||||
ChannelPush.setBadgeNum(unreadCount);
|
ChannelPush.setBadgeNum(unreadCount);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<V2TimCallback> setOfflinePushStatus(
|
||||||
|
{required AppStatus status, int? totalCount}) {
|
||||||
|
|
||||||
|
if (status == AppStatus.foreground) {
|
||||||
|
// 当应用status为前台时,上报doForeground()
|
||||||
|
return TencentImSDKPlugin.v2TIMManager
|
||||||
|
.getOfflinePushManager()
|
||||||
|
.doForeground();
|
||||||
|
} else {
|
||||||
|
// 当应用status为后台时,上报doBackground(),并带上未读数
|
||||||
|
return TencentImSDKPlugin.v2TIMManager
|
||||||
|
.getOfflinePushManager()
|
||||||
|
.doBackground(unreadCount: totalCount ?? 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getLoginStyle() async {
|
getLoginStyle() async {
|
||||||
@ -355,7 +364,6 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initIM() {
|
initIM() {
|
||||||
@ -372,11 +380,11 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|||||||
break;
|
break;
|
||||||
case TIMCallbackType.API_ERROR:
|
case TIMCallbackType.API_ERROR:
|
||||||
//Prints the API error to console, and shows the error message.
|
//Prints the API error to console, and shows the error message.
|
||||||
if(callbackValue.errorCode==20007){
|
if (callbackValue.errorCode == 20007) {
|
||||||
showOKToast("您已被对方拉黑,换个人聊聊天吧~");
|
showOKToast("您已被对方拉黑,换个人聊聊天吧~");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(callbackValue.errorCode==6015){
|
if (callbackValue.errorCode == 6015) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
print(
|
print(
|
||||||
@ -410,7 +418,8 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|||||||
loadBgImage() async {
|
loadBgImage() async {
|
||||||
await precacheImage(precacheImages(_guideList.first), context);
|
await precacheImage(precacheImages(_guideList.first), context);
|
||||||
await precacheImage(precacheImages(_guideList.last), context);
|
await precacheImage(precacheImages(_guideList.last), context);
|
||||||
await precacheImage(AssetImage(getBaseImage('bg')), context,size: Size(Get.width, Get.height));
|
await precacheImage(AssetImage(getBaseImage('bg')), context,
|
||||||
|
size: Size(Get.width, Get.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
precacheImages(String image) {
|
precacheImages(String image) {
|
||||||
@ -419,7 +428,6 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
//填入设计稿中设备的屏幕尺寸,单位dp
|
//填入设计稿中设备的屏幕尺寸,单位dp
|
||||||
// configureDio();
|
// configureDio();
|
||||||
return ScreenUtilInit(
|
return ScreenUtilInit(
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import 'package:circle_app/util/util.dart';
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
|
|
||||||
|
import '../util/SharedPreferencesHelper.dart';
|
||||||
import '../util/device.dart';
|
import '../util/device.dart';
|
||||||
import 'api.dart';
|
import 'api.dart';
|
||||||
import 'package:connectivity/connectivity.dart';
|
import 'package:connectivity/connectivity.dart';
|
||||||
@ -166,16 +167,32 @@ class DioManager {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Response response;
|
Response response;
|
||||||
Options options = Options(
|
|
||||||
|
var options = Options();
|
||||||
|
bool isAgreemement = await getAgreemement();
|
||||||
|
if(isAgreemement){
|
||||||
|
options = Options(
|
||||||
method: methodValues[method], headers: {
|
method: methodValues[method], headers: {
|
||||||
"Authorization": await getAuthorization(),
|
"Authorization": await getAuthorization(),
|
||||||
'VersionName': await getVersionName(),
|
'VersionName': await getVersionName(),
|
||||||
'VersionCode': await getVersionCode(),
|
'VersionCode': await getVersionCode(),
|
||||||
'OsVersion': await getDeviceId(),
|
|
||||||
'Platform': Platform.isIOS ? '1' : '0',
|
'Platform': Platform.isIOS ? '1' : '0',
|
||||||
|
'OsVersion': await getDeviceId(),
|
||||||
'Imei': await getImei(),
|
'Imei': await getImei(),
|
||||||
'Brand': await getBrand(),
|
'Brand': await getBrand(),
|
||||||
});
|
});
|
||||||
|
}else{
|
||||||
|
options = Options(
|
||||||
|
method: methodValues[method], headers: {
|
||||||
|
"Authorization": await getAuthorization(),
|
||||||
|
'VersionName': await getVersionName(),
|
||||||
|
'VersionCode': await getVersionCode(),
|
||||||
|
'Platform': Platform.isIOS ? '1' : '0',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
print(">>>>>$params");
|
print(">>>>>$params");
|
||||||
|
|
||||||
/// 不同请求方法,不同的请求参数,按实际项目需求分.
|
/// 不同请求方法,不同的请求参数,按实际项目需求分.
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class SharedPreferencesHelper {
|
class SharedPreferencesHelper {
|
||||||
@ -13,6 +15,8 @@ class SharedPreferencesHelper {
|
|||||||
|
|
||||||
static const LOGINPHONE = 'loginPhone';
|
static const LOGINPHONE = 'loginPhone';
|
||||||
|
|
||||||
|
static const AGREEMENT = 'agreement';
|
||||||
|
|
||||||
|
|
||||||
static SharedPreferencesHelper? _instance;
|
static SharedPreferencesHelper? _instance;
|
||||||
static SharedPreferences? _preferences;
|
static SharedPreferences? _preferences;
|
||||||
@ -44,6 +48,10 @@ class SharedPreferencesHelper {
|
|||||||
final prefs = preferences;
|
final prefs = preferences;
|
||||||
prefs?.setInt(key, value) ?? 0;
|
prefs?.setInt(key, value) ?? 0;
|
||||||
}
|
}
|
||||||
|
setBool(String key, bool value) async {
|
||||||
|
final prefs = preferences;
|
||||||
|
prefs?.setBool(key, value) ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
int getInt(String key) {
|
int getInt(String key) {
|
||||||
final prefs = preferences;
|
final prefs = preferences;
|
||||||
@ -59,6 +67,8 @@ class SharedPreferencesHelper {
|
|||||||
return preferences?.getInt(SharedPreferencesHelper.USERID).toString() ?? '';
|
return preferences?.getInt(SharedPreferencesHelper.USERID).toString() ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool? getBool(String key) {
|
bool? getBool(String key) {
|
||||||
final prefs = preferences;
|
final prefs = preferences;
|
||||||
return prefs?.getBool(key);
|
return prefs?.getBool(key);
|
||||||
|
|||||||
@ -114,3 +114,13 @@ Future<String> getAuthorization() async {
|
|||||||
token = sharedPreferences.getString(SharedPreferencesHelper.AUTHORIZATION)??"";
|
token = sharedPreferences.getString(SharedPreferencesHelper.AUTHORIZATION)??"";
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> getAgreemement() async {
|
||||||
|
if(Platform.isIOS){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool isAgreemement =false;
|
||||||
|
SharedPreferences sharedPreferences =await SharedPreferences.getInstance();
|
||||||
|
isAgreemement = sharedPreferences.getBool(SharedPreferencesHelper.AGREEMENT)??false;
|
||||||
|
return isAgreemement;
|
||||||
|
}
|
||||||
|
|||||||
@ -153,10 +153,12 @@ String convertToTenThousand(int number) {
|
|||||||
pushLoginPage() async {
|
pushLoginPage() async {
|
||||||
await logoutIM();
|
await logoutIM();
|
||||||
SharedPreferencesHelper.getInstance().then((sharedPreferences) {
|
SharedPreferencesHelper.getInstance().then((sharedPreferences) {
|
||||||
String loginPhone = sharedPreferences.getString(SharedPreferencesHelper.LOGINPHONE);
|
bool agreement = sharedPreferences.getBool(SharedPreferencesHelper.AGREEMENT)??false;
|
||||||
|
String loginPhone = sharedPreferences.getString(SharedPreferencesHelper.LOGINPHONE)??"";
|
||||||
print(loginPhone);
|
print(loginPhone);
|
||||||
sharedPreferences.clear();
|
sharedPreferences.clear();
|
||||||
sharedPreferences.setString(SharedPreferencesHelper.LOGINPHONE, loginPhone);
|
sharedPreferences.setString(SharedPreferencesHelper.LOGINPHONE, loginPhone);
|
||||||
|
sharedPreferences.setBool(SharedPreferencesHelper.AGREEMENT, agreement);
|
||||||
});
|
});
|
||||||
|
|
||||||
Get.offAllNamed(AppRoutes.Login);
|
Get.offAllNamed(AppRoutes.Login);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user