火灾报警改为使用web socket触发弹窗

hmxc
张萌 3 years ago
parent 5183b0623b
commit 59544d4747

@ -1,6 +1,9 @@
// Flutter imports: // Flutter imports:
import 'package:aku_community_manager/provider/message_provider.dart'; import 'package:aku_community_manager/provider/message_provider.dart';
import 'package:aku_community_manager/tools/user_tool.dart'; import 'package:aku_community_manager/tools/user_tool.dart';
import 'package:aku_community_manager/utils/websocket/fier_dialog.dart';
import 'package:aku_community_manager/utils/websocket/web_socket_util.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -26,6 +29,13 @@ void main() async {
JPush jpush = new JPush(); JPush jpush = new JPush();
const isProduct = const bool.fromEnvironment('ISPRODUCT'); const isProduct = const bool.fromEnvironment('ISPRODUCT');
DevUtil.setDev(!isProduct); DevUtil.setDev(!isProduct);
WebSocketUtil().initWebSocket(
// heartDuration: Duration(seconds: 5),
onError: (e) {
LoggerData.addData(e);
}, onReceiveMes: (message) async {
await FireDialog.fireAlert(message);
});
jpush.addEventHandler( jpush.addEventHandler(
// //
onReceiveNotification: (Map<String, dynamic>? message) async { onReceiveNotification: (Map<String, dynamic>? message) async {

@ -4,6 +4,7 @@ import 'dart:io';
// Flutter imports: // Flutter imports:
import 'package:aku_community_manager/models/user/user_info_model.dart'; import 'package:aku_community_manager/models/user/user_info_model.dart';
import 'package:aku_community_manager/provider/message_provider.dart'; import 'package:aku_community_manager/provider/message_provider.dart';
import 'package:aku_community_manager/utils/websocket/web_socket_util.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// Package imports: // Package imports:
@ -20,7 +21,6 @@ import 'package:aku_community_manager/utils/network/base_file_model.dart';
import 'package:aku_community_manager/utils/network/base_model.dart'; import 'package:aku_community_manager/utils/network/base_model.dart';
import 'package:aku_community_manager/utils/network/net_util.dart'; import 'package:aku_community_manager/utils/network/net_util.dart';
// //
class UserProvider extends ChangeNotifier { class UserProvider extends ChangeNotifier {
bool _isLogin = false; bool _isLogin = false;
@ -35,6 +35,8 @@ class UserProvider extends ChangeNotifier {
await HiveStore.appBox!.put('login', true); await HiveStore.appBox!.put('login', true);
_profileModel = await updateProfile(); _profileModel = await updateProfile();
_infoModel = await updateUserInfo(); _infoModel = await updateUserInfo();
WebSocketUtil().setUser(infoModel!.id.toString());
WebSocketUtil().startWebSocket();
// await setCurrentHouse((_userDetailModel?.estateNames?.isEmpty ?? true) // await setCurrentHouse((_userDetailModel?.estateNames?.isEmpty ?? true)
// ? '' // ? ''
// : _userDetailModel?.estateNames?.first); // : _userDetailModel?.estateNames?.first);
@ -48,7 +50,8 @@ class UserProvider extends ChangeNotifier {
///profile ///profile
Future<UserProfileModel?> updateProfile() async { Future<UserProfileModel?> updateProfile() async {
final messageProvider = Provider.of<MessageProvider>(Get.context!,listen: false); final messageProvider =
Provider.of<MessageProvider>(Get.context!, listen: false);
messageProvider.updateMessage(); messageProvider.updateMessage();
BaseModel? model = await NetUtil().get(API.user.profile); BaseModel? model = await NetUtil().get(API.user.profile);
if (model.data == null) if (model.data == null)
@ -72,6 +75,7 @@ class UserProvider extends ChangeNotifier {
/// ///
logout() async { logout() async {
await NetUtil().get(API.auth.logout, showMessage: true); await NetUtil().get(API.auth.logout, showMessage: true);
WebSocketUtil().closeWebSocket();
NetUtil().logout(); NetUtil().logout();
_isLogin = false; _isLogin = false;
await HiveStore.appBox!.delete('token'); await HiveStore.appBox!.delete('token');
@ -90,10 +94,6 @@ class UserProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
/// ///
setNickName(String name) { setNickName(String name) {
_infoModel!.nickName = name; _infoModel!.nickName = name;

@ -10,6 +10,7 @@ import 'package:bot_toast/bot_toast.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:get/get.dart' hide Response; import 'package:get/get.dart' hide Response;
import 'package:pin_input_text_field/pin_input_text_field.dart'; import 'package:pin_input_text_field/pin_input_text_field.dart';
import 'package:power_logger/power_logger.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
// Project imports: // Project imports:
@ -120,19 +121,24 @@ class _LoginSMSPageState extends State<LoginSMSPage> {
onChanged: (text) async { onChanged: (text) async {
if (text.length == 6) { if (text.length == 6) {
Function cancel = BotToast.showLoading(); Function cancel = BotToast.showLoading();
Response response = await NetUtil().dio!.post( try {
API.auth.login, Response response = await NetUtil().dio!.post(
data: {'tel': widget.phone, 'code': text}, API.auth.login,
); data: {'tel': widget.phone, 'code': text},
if (response.data['status'] == true) { );
await userProvider.setLogin(response.data['token']); if (response.data['status'] == true) {
await userProvider.setLogin(response.data['token']);
cancel();
Get.offAll(HomePage());
} else {
_textEditingController.clear();
cancel();
BotToast.showText(text: '登陆失败');
Get.off(LoginPage());
}
} catch (e) {
LoggerData.addData(e);
cancel(); cancel();
Get.offAll(HomePage());
} else {
_textEditingController.clear();
cancel();
BotToast.showText(text: '登陆失败');
Get.off(LoginPage());
} }
} }

@ -64,7 +64,7 @@ class _SplashPageState extends State<SplashPage> {
Future.delayed(Duration(milliseconds: 2000), () async { Future.delayed(Duration(milliseconds: 2000), () async {
await _initOp(); await _initOp();
Get.off(HomePage()); Get.off(()=>HomePage());
}); });
} }

@ -1,14 +1,11 @@
// Dart imports: // Dart imports:
import 'dart:convert'; import 'dart:convert';
import 'package:aku_community_manager/utils/websocket/fier_dialog.dart';
// Flutter imports: // Flutter imports:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
// Package imports: // Package imports:
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:velocity_x/velocity_x.dart';
class JpushMessageParse { class JpushMessageParse {
final Map<String, dynamic> message; final Map<String, dynamic> message;
@ -28,36 +25,12 @@ class JpushMessageParse {
type = _innerMap['type'] ?? '0'; type = _innerMap['type'] ?? '0';
switch (type) { switch (type) {
case '1': case '1':
await fireAlert(subTitle!); await FireDialog.fireAlert(subTitle!);
break; break;
default: default:
} }
} }
} }
Future fireAlert(String subTitle) async {
await Get.dialog(
CupertinoAlertDialog(
title: Text('发现火灾!请立刻组织疏散人群!'),
content: Column(
children: [
Text(subTitle),
10.w.heightBox,
Icon(
CupertinoIcons.bell_fill,
color: Colors.red,
size: 48.w,
),
],
),
actions: [
CupertinoDialogAction(
child: Text('确认'),
onPressed: () => Get.back(),
),
],
),
barrierDismissible: false,
);
}
} }

@ -0,0 +1,34 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:velocity_x/velocity_x.dart';
class FireDialog {
static Future fireAlert(String subTitle) async {
await Get.dialog(
CupertinoAlertDialog(
title: Text('发现火灾!请立刻组织疏散人群!'),
content: Column(
children: [
Text(subTitle),
10.w.heightBox,
Icon(
CupertinoIcons.bell_fill,
color: Colors.red,
size: 48.w,
),
],
),
actions: [
CupertinoDialogAction(
child: Text('确认'),
onPressed: () => Get.back(),
),
],
),
barrierDismissible: false,
);
}
}

@ -1044,7 +1044,7 @@ packages:
source: hosted source: hosted
version: "3.0.1" version: "3.0.1"
web_socket_channel: web_socket_channel:
dependency: transitive dependency: "direct main"
description: description:
name: web_socket_channel name: web_socket_channel
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"

@ -28,6 +28,8 @@ dependencies:
qr_code_scanner: ^0.4.0-nullsafety.0 qr_code_scanner: ^0.4.0-nullsafety.0
#toast #toast
bot_toast: ^4.0.1 bot_toast: ^4.0.1
#websocket
web_socket_channel: ^2.1.0
extended_text: ^5.0.4 extended_text: ^5.0.4

Loading…
Cancel
Save