diff --git a/lib/pages/setting_page/settings_page.dart b/lib/pages/setting_page/settings_page.dart index b4220ff1..ff3c019c 100644 --- a/lib/pages/setting_page/settings_page.dart +++ b/lib/pages/setting_page/settings_page.dart @@ -1,3 +1,6 @@ +import 'package:aku_community/utils/developer_util.dart'; +import 'package:aku_community/utils/websocket/web_socket_util.dart'; +import 'package:aku_community/widget/others/user_tool.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -160,9 +163,35 @@ class _SettingsPageState extends State { height: 1.w, )), 53.hb, + if (DeveloperUtil.dev) _closeFireAlert(), + if (DeveloperUtil.dev) 53.hb, _quitButton(), ], ), ); } + + Widget _closeFireAlert() { + return Container( + color: Colors.white, + padding: EdgeInsets.symmetric(vertical: 12.w, horizontal: 64.w), + child: Row( + children: [ + '开启火灾报警'.text.size(28.sp).color(ktextPrimary).bold.make().expand(), + CupertinoSwitch( + value: UserTool.appProveider.fireAlert, + onChanged: (value) { + UserTool.appProveider.setFireAlert(value); + if (UserTool.appProveider.fireAlert) { + WebSocketUtil().startWebSocket(); + WebSocketUtil().setPrintHeart(value); + } else { + WebSocketUtil().closeWebSocket(); + } + setState(() {}); + }) + ], + ), + ); + } } diff --git a/lib/provider/app_provider.dart b/lib/provider/app_provider.dart index 21f58dd2..fdbf4e44 100644 --- a/lib/provider/app_provider.dart +++ b/lib/provider/app_provider.dart @@ -250,4 +250,11 @@ class AppProvider extends ChangeNotifier { .toList(); notifyListeners(); } + //设置火灾报警开关 + bool _fireAlert = true; + bool get fireAlert => _fireAlert; + void setFireAlert(bool value) { + _fireAlert = value; + notifyListeners(); + } } diff --git a/lib/utils/websocket/web_socket_util.dart b/lib/utils/websocket/web_socket_util.dart index b3ffcf25..7b73d60d 100644 --- a/lib/utils/websocket/web_socket_util.dart +++ b/lib/utils/websocket/web_socket_util.dart @@ -205,4 +205,9 @@ class WebSocketUtil { print(data); } } + + ///控制台输出心跳连接 + void setPrintHeart(bool value) { + this._consolePrint = value; + } }