diff --git a/lib/pages/services/old_age/old_age_support_list_page.dart b/lib/pages/services/old_age/old_age_support_list_page.dart index e5c7151a..cbca5f59 100644 --- a/lib/pages/services/old_age/old_age_support_list_page.dart +++ b/lib/pages/services/old_age/old_age_support_list_page.dart @@ -200,7 +200,7 @@ class _OldAgeSupportListPageState extends State { .color( select ? Colors.white : Colors.black.withOpacity(0.65)) .make(), - ], + ], ), Spacer(), Container( diff --git a/lib/provider/clock_timer_provider.dart b/lib/provider/clock_timer_provider.dart index aa33dd8b..4d6b66e8 100644 --- a/lib/provider/clock_timer_provider.dart +++ b/lib/provider/clock_timer_provider.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; -class ClockTimerProvider extends ChangeNotifier{ +class ClockTimerProvider extends ChangeNotifier { ///登录页验证码计时器 int second = 60; bool timerStart = false; @@ -10,6 +10,9 @@ class ClockTimerProvider extends ChangeNotifier{ void startTimer() { timerStart = true; + if (timer != null) { + return; + } timer = Timer.periodic(Duration(seconds: 1), (timer) { if (second > 0) { second--; @@ -27,4 +30,4 @@ class ClockTimerProvider extends ChangeNotifier{ timer = null; notifyListeners(); } -} \ No newline at end of file +} diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index fc7afc84..0ac877d5 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -30,9 +30,6 @@ class UserProvider extends ChangeNotifier { Future init() async { if (isLogin) { await updateUserInfo(); - WebSocketUtil().setUser(userInfoModel!.id.toString()); - WebSocketUtil().setCommunityCode(userInfoModel!.communityCode); - WebSocketUtil().setNickName(userInfoModel!.nickName!); WebSocketUtil().startWebSocket(); await updateMyHouseInfo(); diff --git a/lib/utils/websocket/web_socket_util.dart b/lib/utils/websocket/web_socket_util.dart index 65b504a8..4f7b9146 100644 --- a/lib/utils/websocket/web_socket_util.dart +++ b/lib/utils/websocket/web_socket_util.dart @@ -7,9 +7,6 @@ import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:aku_new_community/widget/others/user_tool.dart'; -// const String baseUri = 'wss://shop.kaidalai.cn/websocket/app'; -const String baseUri = 'wss://saas.kaidalai.cn/websocket/app'; - enum SOCKETSTATUS { CONNECTED, //已连接 BREAKOFF, //已断开 @@ -28,9 +25,10 @@ class WebSocketUtil { IOWebSocketChannel? _webSocket; ///用户设置不同的服务器地址 - String _user = 'admin'; - String _communityCode = 'communityCode'; - String _nickName = 'nickName'; + static const String baseUri = 'wss://saas.kaidalai.cn/websocket/app'; + + String get urlAddress => + '$baseUri/${UserTool.userProvider.userInfoModel?.communityCode}/${UserTool.userProvider.userInfoModel?.nickName}'; ///连接状态 SOCKETSTATUS _socketStatus = SOCKETSTATUS.CLOSED; @@ -86,32 +84,19 @@ class WebSocketUtil { print('——————————webSocket init ——————————'); } - ///设置用户 - void setUser(String user) { - this._user = user; - } - - void setCommunityCode(String communityCode) { - this._communityCode = communityCode; - } - - void setNickName(String nickName) { - this._nickName = nickName; - } - ///开启websocket void startWebSocket() { closeWebSocket(); try { - _webSocket = IOWebSocketChannel.connect( - Uri.parse('$baseUri/$_communityCode/$_nickName')); - print('webSocket已连接服务器:$baseUri/$_user'); + _webSocket = IOWebSocketChannel.connect(Uri.parse(urlAddress)); + print('webSocket已连接服务器:$urlAddress'); _socketStatus = SOCKETSTATUS.CONNECTED; endReconnect(); onStart?.call(); _webSocket!.stream.listen( - (event) => webSocketReceiveMessage(event as String), - onError: webSocketOnError,); + (event) => webSocketReceiveMessage(event as String), + onError: webSocketOnError, + ); initHeartBeat(); } catch (e) { BotToast.showText(text: 'webSocket连接失败');