kaciya 5 年前
父节点
当前提交
c50d297c93
共有 2 个文件被更改,包括 44 次插入34 次删除
  1. +33
    -28
      lib/utils/NetUtil.dart
  2. +11
    -6
      lib/utils/screen.dart

+ 33
- 28
lib/utils/NetUtil.dart 查看文件

@@ -61,9 +61,11 @@ class NetWork {
Timer heartTimer; Timer heartTimer;
Timer sendTimer; Timer sendTimer;
Timer connectServerTimer; //尝试连接服务器 Timer connectServerTimer; //尝试连接服务器
Timer loginTimer; //登录计时器
Timer loginTimer; //登录
// 计时器 // 计时器
Timer iosBgTimer; //登录计时器 Timer iosBgTimer; //登录计时器
bool isInit = false; bool isInit = false;
String host; String host;
@@ -80,9 +82,6 @@ class NetWork {
HttpUtil().post('/service/config', data: data).then((res) { HttpUtil().post('/service/config', data: data).then((res) {
print('获取聊天服务器地址成功'); print('获取聊天服务器地址成功');
res = json.decode(res.toString()); res = json.decode(res.toString());
if (res == null) {
return;
}
if (res['code'] == 0) { if (res['code'] == 0) {
var config = res['data'][0]; var config = res['data'][0];
@@ -161,7 +160,7 @@ class NetWork {
loginTimer?.cancel(); loginTimer?.cancel();
MsgHandler.flushCacheMsg(); MsgHandler.flushCacheMsg();
UploadUtil().setUploadUrl(msgContent.httpAddr); UploadUtil().setUploadUrl(msgContent.httpAddr);
GroupInfoMgr().checkGroupValid();
GroupInfoMgr().checkGroupValid();
} else { } else {
_stateBloc.addState(ChatState.loginFailed); _stateBloc.addState(ChatState.loginFailed);
print('登录失败${msgContent.errorCode}'); print('登录失败${msgContent.errorCode}');
@@ -305,37 +304,43 @@ class NetWork {
} }
reallySingOut() {
print('用户登出');
//清缓存
isNormalClose = true;
reallyClose();
}
reallyClose() {
reallyClose() async{
print('清除连接状态');
isNormalClose=true;
isConnecting = false;
isConnect = false;
isLogin = false;
heartOutCount = 0;
sendTimer?.cancel();
heartTimer?.cancel();
if(iosBgTimer==null){
debugPrint('#### ios bg 没有计时器--计时器你启动');
iosBgTimer = Timer(Duration(seconds: 20), () async{
debugPrint('#### ios bg ios后台关闭socket连接');
isNormalClose=true;
isConnecting = false;
isConnect = false;
isLogin = false;
heartOutCount = 0;
sendTimer?.cancel();
heartTimer?.cancel();
loginTimer?.cancel();
print('清除计时器');
connectServerTimer?.cancel();
loginTimer?.cancel();
connectServerTimer?.cancel();
if (channel != null) {
var result = await channel.sink.close();
print('result: $result');
channel = null;
if (channel != null) {
await channel.sink.close();
channel = null;
}
});
}else{
debugPrint('#### ios bg 已有计时器');
} }
} }
checkConnect() { checkConnect() {
debugPrint(' ios bg 取消计时器');
iosBgTimer?.cancel();
if (isInit && !isConnect && !isConnecting) { if (isInit && !isConnect && !isConnecting) {
reconnect(); reconnect();
} else { } else {
@@ -410,7 +415,7 @@ class NetWork {
//清缓存 //清缓存
ChatDataMgr().logout(); ChatDataMgr().logout();
MsgHandler.clear(); MsgHandler.clear();
isNormalClose = true; isNormalClose = true;
close(); close();
} }


+ 11
- 6
lib/utils/screen.dart 查看文件

@@ -63,12 +63,12 @@ fixedText(data, {Color color, double fontSize, FontWeight fontWeight}) {
extendedText(String text, extendedText(String text,
{Color color = Colors.blue, {Color color = Colors.blue,
double fontSize = 14,
selectionEnabled = false,
double emojisize = 20.0,
Function hideKeyboard,
fontWeight,int maxLines,
Function onSpecialTextTap
double fontSize = 14,
selectionEnabled = false,
double emojisize = 20.0,
Function hideKeyboard,
fontWeight,int maxLines,
Function onSpecialTextTap
}) { }) {
return ExtendedText( return ExtendedText(
text, text,
@@ -91,3 +91,8 @@ setStatusBar(){
systemNavigationBarColor: Colors.white, systemNavigationBarColor: Colors.white,
systemNavigationBarIconBrightness: Brightness.dark)); systemNavigationBarIconBrightness: Brightness.dark));
} }
debugPrint(dynamic msg){
print('###${DateTime.now()}####### '+msg);
}

正在加载...
取消
保存