diff --git a/lib/utils/NetUtil.dart b/lib/utils/NetUtil.dart index 3978664..c7f4c3e 100644 --- a/lib/utils/NetUtil.dart +++ b/lib/utils/NetUtil.dart @@ -61,9 +61,11 @@ class NetWork { Timer heartTimer; Timer sendTimer; Timer connectServerTimer; //尝试连接服务器 - Timer loginTimer; //登录计时器 + Timer loginTimer; //登录 + // 计时器 Timer iosBgTimer; //登录计时器 + bool isInit = false; String host; @@ -80,9 +82,6 @@ class NetWork { HttpUtil().post('/service/config', data: data).then((res) { print('获取聊天服务器地址成功'); res = json.decode(res.toString()); - if (res == null) { - return; - } if (res['code'] == 0) { var config = res['data'][0]; @@ -161,7 +160,7 @@ class NetWork { loginTimer?.cancel(); MsgHandler.flushCacheMsg(); UploadUtil().setUploadUrl(msgContent.httpAddr); - GroupInfoMgr().checkGroupValid(); + GroupInfoMgr().checkGroupValid(); } else { _stateBloc.addState(ChatState.loginFailed); 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() { + debugPrint(' ios bg 取消计时器'); + iosBgTimer?.cancel(); + if (isInit && !isConnect && !isConnecting) { reconnect(); } else { @@ -410,7 +415,7 @@ class NetWork { //清缓存 ChatDataMgr().logout(); MsgHandler.clear(); - + isNormalClose = true; close(); } diff --git a/lib/utils/screen.dart b/lib/utils/screen.dart index 5ec556a..aea9410 100644 --- a/lib/utils/screen.dart +++ b/lib/utils/screen.dart @@ -63,12 +63,12 @@ fixedText(data, {Color color, double fontSize, FontWeight fontWeight}) { extendedText(String text, {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( text, @@ -91,3 +91,8 @@ setStatusBar(){ systemNavigationBarColor: Colors.white, systemNavigationBarIconBrightness: Brightness.dark)); } + + +debugPrint(dynamic msg){ + print('###${DateTime.now()}####### '+msg); +}