Files
tuiche/lib/pages/setting/common_mesaage_setting.dart
2026-04-07 14:49:31 +08:00

917 lines
52 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:async';
import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/color/ServiceConstant.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/common/util/requestWithLog.dart';
import 'package:vbvs_app/component/base/GradientSwitch.dart';
import 'package:vbvs_app/component/tool/NewTopSlideNotification.dart';
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/controller/message/common_message_setting_controller.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
import 'package:flutter/services.dart';
class CommonMessageSettingPage extends StatefulWidget {
CommonMessageSettingPage({super.key});
@override
State<CommonMessageSettingPage> createState() =>
_CommonMessageSettingPageState();
}
class _CommonMessageSettingPageState extends State<CommonMessageSettingPage> {
final ThemeController themeController = Get.find();
CommonMessageSettingController commonMessageSettingController = Get.find();
@override
void initState() {
super.initState();
_fetchDeviceList();
}
Future<void> _fetchDeviceList() async {
String serviceAddress = ServiceConstant.service_address;
String serviceName = ServiceConstant.server_service;
String serviceApi = ServiceConstant.user_setting;
String type = "user_message_setting";
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type";
requestWithLog(
logTitle: "查询用户消息配置13",
method: MyHttpMethod.get,
queryUrl: queryUrl,
onSuccess: (res) {
if (res.data == null || res.data.isEmpty) {
var data = {
"type": type,
"setting": 1,
"appSetting": 1,
"serviceSetting": 1,
"tipSetting": 1,
"deviceUpgradeSetting": 1,
"deviceIssueSetting": 1,
};
requestWithLog(
logTitle: "更新用户消息配置",
method: MyHttpMethod.put,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
requestWithLog(
logTitle: "查询用户消息配置14",
method: MyHttpMethod.get,
queryUrl: queryUrl,
onSuccess: (res) {
if (res.data != null && res.data.isNotEmpty) {
var datalist = res.data;
commonMessageSettingController.model.setting =
datalist['setting'];
commonMessageSettingController.model.appSetting =
datalist['appSetting'];
commonMessageSettingController.model.serviceSetting =
datalist['serviceSetting'];
commonMessageSettingController.model.tipSetting =
datalist['tipSetting'];
commonMessageSettingController.model.deviceUpgradeSetting =
datalist['deviceUpgradeSetting'];
commonMessageSettingController.model.deviceIssueSetting =
datalist['deviceIssueSetting'];
commonMessageSettingController.updateAll();
}
},
);
//
},
);
} else {
var datalist = res.data;
commonMessageSettingController.model.setting = datalist['setting'];
commonMessageSettingController.model.appSetting =
datalist['appSetting'];
commonMessageSettingController.model.serviceSetting =
datalist['serviceSetting'];
commonMessageSettingController.model.tipSetting =
datalist['tipSetting'];
commonMessageSettingController.model.deviceUpgradeSetting =
datalist['deviceUpgradeSetting'];
commonMessageSettingController.model.deviceIssueSetting =
datalist['deviceIssueSetting'];
commonMessageSettingController.updateAll();
}
},
onFailure: (res) {
print(res);
},
);
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, bodysize) => GestureDetector(
// onTap: () => FocusScope.of(context).unfocus(),,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(getBackgroundImageNoImage()),
fit: BoxFit.fill,
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
systemOverlayStyle: SystemUiOverlayStyle(
statusBarColor: Colors.transparent, // 状态栏背景色
statusBarIconBrightness: Brightness.light, // 图标颜色Android
statusBarBrightness: Brightness.light, // 图标颜色iOS
),
backgroundColor: themeController.currentColor.sc5,
automaticallyImplyLeading: false,
iconTheme: IconThemeData(
color: themeController.currentColor.sc3,
),
titleSpacing: 0,
title: Container(
width: double.infinity,
height: 180.rpx,
child: Stack(
alignment: Alignment.center,
children: [
/// 居中标题
Text(
'通知设置'.tr,
style: TextStyle(
fontFamily: 'ReadexPro',
color: themeController.currentColor.sc3,
letterSpacing: 0,
fontSize: 30.rpx,
),
),
Positioned(
left: 0,
child: returnIconButtomAddCallback(() {}),
),
],
),
),
actions: [],
centerTitle: false,
),
body: GestureDetector(
child: SafeArea(
top: true,
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 0, 0.rpx, 0),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 0),
child: Container(
width: double.infinity,
constraints: BoxConstraints(
minHeight: 90.rpx,
),
decoration: BoxDecoration(
color: themeController.currentColor.sc5),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 15.rpx, 30.rpx, 15.rpx),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
"全部通知".tr,
style: TextStyle(
color:
themeController.currentColor.sc3,
fontSize: AppConstants()
.title_text_fontSize),
),
),
Obx(() {
return GradientSwitch(
value: commonMessageSettingController
.model.setting ==
1
? true
: false,
onChanged: (val) {
if (val == false) {
NewTopSlideNotification.show(
text: "注意!关闭后将无法接受任何消息".tr,
textColor: themeController
.currentColor.sc9,
duration: Duration(seconds: 3),
);
}
String serviceAddress =
ServiceConstant.service_address;
String serviceName =
ServiceConstant.server_service;
String serviceApi =
ServiceConstant.user_setting;
String type = "user_message_setting";
String queryUrl =
"${serviceAddress}${serviceName}${serviceApi}";
var data = {
"type": type,
"setting": val == true ? 1 : 0,
"appSetting":
commonMessageSettingController
.model.appSetting,
"serviceSetting":
commonMessageSettingController
.model.serviceSetting,
"tipSetting":
commonMessageSettingController
.model.tipSetting,
"deviceUpgradeSetting":
commonMessageSettingController
.model.deviceUpgradeSetting,
"deviceIssueSetting":
commonMessageSettingController
.model.deviceIssueSetting,
};
requestWithLog(
logTitle: "更新消息推送状态",
method: MyHttpMethod.put,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
_fetchDeviceList();
commonMessageSettingController
.updateAll();
});
},
activeGradient: LinearGradient(
colors: [
themeController.currentColor.sc1,
themeController.currentColor.sc2
],
),
activeThumbColor: Colors.white,
inactiveThumbColor:
stringToColor("#A2A4A9"),
inactiveColor: stringToColor("#161B28"),
);
}),
],
),
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
0.rpx, 21.rpx, 0.rpx, 0),
child: Container(
decoration: BoxDecoration(
color: themeController.currentColor.sc5,
borderRadius: BorderRadius.circular(0),
),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 40.rpx, 30.rpx, 54.rpx),
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
"APP消息".tr,
style: TextStyle(
color: themeController
.currentColor.sc3,
fontSize: AppConstants()
.title_text_fontSize),
),
),
Obx(() {
return GradientSwitch(
value: commonMessageSettingController
.model.setting ==
1
? (commonMessageSettingController
.model.appSetting ==
1
? true
: false)
: false,
onChanged: (val) {
if (commonMessageSettingController
.model.setting ==
0) {
TopSlideNotification.show(
context,
text: "请先打开全部消息配置".tr,
textColor: themeController
.currentColor.sc9);
return;
}
String serviceAddress =
ServiceConstant
.service_address;
String serviceName =
ServiceConstant
.server_service;
String serviceApi =
ServiceConstant.user_setting;
String type =
"user_message_setting";
String queryUrl =
"${serviceAddress}${serviceName}${serviceApi}";
var data = {
"type": type,
"setting":
commonMessageSettingController
.model.setting,
"appSetting":
val == true ? 1 : 0,
"serviceSetting":
commonMessageSettingController
.model.serviceSetting,
"tipSetting":
commonMessageSettingController
.model.tipSetting,
"deviceUpgradeSetting":
commonMessageSettingController
.model
.deviceUpgradeSetting,
"deviceIssueSetting":
commonMessageSettingController
.model
.deviceIssueSetting,
};
requestWithLog(
logTitle: "更新消息推送状态",
method: MyHttpMethod.put,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
_fetchDeviceList();
commonMessageSettingController
.updateAll();
});
},
activeGradient: LinearGradient(
colors: [
themeController
.currentColor.sc1,
themeController.currentColor.sc2
],
),
activeThumbColor: Colors.white,
inactiveThumbColor:
stringToColor("#A2A4A9"),
inactiveColor:
stringToColor("#161B28"),
);
}),
],
),
Text(
// AppConstants().ent_type == 1
// ? "通用APP消息介绍".tr
// : "打开“欢睡科技”APP可以查看消息内容",
"通用APP消息介绍".tr,
style: TextStyle(
color:
themeController.currentColor.sc4,
fontSize: AppConstants()
.normal_text_fontSize),
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
"服务号消息".tr,
style: TextStyle(
color: themeController
.currentColor.sc3,
fontSize: AppConstants()
.title_text_fontSize),
),
),
Obx(() {
return GradientSwitch(
value: commonMessageSettingController
.model.setting ==
1
? (commonMessageSettingController
.model
.serviceSetting ==
1
? true
: false)
: false,
onChanged: (val) {
if (commonMessageSettingController
.model.setting ==
0) {
TopSlideNotification.show(
context,
text: "请先打开全部消息配置".tr,
textColor: themeController
.currentColor.sc9);
return;
}
String serviceAddress =
ServiceConstant
.service_address;
String serviceName =
ServiceConstant
.server_service;
String serviceApi =
ServiceConstant.user_setting;
String type =
"user_message_setting";
String queryUrl =
"${serviceAddress}${serviceName}${serviceApi}";
var data = {
"type": type,
"setting":
commonMessageSettingController
.model.setting,
"appSetting":
commonMessageSettingController
.model.appSetting,
"serviceSetting":
val == true ? 1 : 0,
"tipSetting":
commonMessageSettingController
.model.tipSetting,
"deviceUpgradeSetting":
commonMessageSettingController
.model
.deviceUpgradeSetting,
"deviceIssueSetting":
commonMessageSettingController
.model
.deviceIssueSetting,
};
requestWithLog(
logTitle: "更新消息推送状态",
method: MyHttpMethod.put,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
_fetchDeviceList();
commonMessageSettingController
.updateAll();
});
},
activeGradient: LinearGradient(
colors: [
themeController
.currentColor.sc1,
themeController.currentColor.sc2
],
),
activeThumbColor: Colors.white,
inactiveThumbColor:
stringToColor("#A2A4A9"),
inactiveColor:
stringToColor("#161B28"),
);
}),
],
),
Text(
// AppConstants().ent_type == 1
// ? "通用服务号消息介绍".tr
// : "无需打开“欢睡科技”APP关注欢睡智能睡眠研究所服务号后微信内即可接收消息推送",
"通用服务号消息介绍".tr,
style: TextStyle(
color:
themeController.currentColor.sc4,
fontSize: AppConstants()
.normal_text_fontSize),
),
].divide(SizedBox(
height: 49.rpx,
)),
),
),
),
),
),
// Padding(
// padding:
// EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 0),
// child: Container(
// width: double.infinity,
// constraints: BoxConstraints(
// minHeight: 90.rpx,
// ),
// decoration: BoxDecoration(
// color: themeController.currentColor.sc5),
// child: Padding(
// padding: EdgeInsetsDirectional.fromSTEB(
// 30.rpx, 15.rpx, 30.rpx, 15.rpx),
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Row(
// mainAxisSize: MainAxisSize.max,
// mainAxisAlignment:
// MainAxisAlignment.spaceBetween,
// children: [
// Expanded(
// child: Text(
// "绑定操作提示".tr,
// style: TextStyle(
// color: themeController
// .currentColor.sc3,
// fontSize: AppConstants()
// .title_text_fontSize),
// ),
// ),
// Obx(() {
// return GradientSwitch(
// value: commonMessageSettingController
// .model.setting ==
// 1
// ? (commonMessageSettingController
// .model.tipSetting ==
// 1
// ? true
// : false)
// : false,
// onChanged: (val) {
// if (commonMessageSettingController
// .model.setting ==
// 0) {
// TopSlideNotification.show(
// context,
// text: "请先打开全部消息配置".tr,
// textColor: themeController
// .currentColor.sc9);
// return;
// }
// String serviceAddress =
// ServiceConstant
// .service_address;
// String serviceName =
// ServiceConstant
// .server_service;
// String serviceApi =
// ServiceConstant.user_setting;
// String type =
// "user_message_setting";
// String queryUrl =
// "${serviceAddress}${serviceName}${serviceApi}";
// var data = {
// "type": type,
// "setting":
// commonMessageSettingController
// .model.setting,
// "appSetting":
// commonMessageSettingController
// .model.appSetting,
// "serviceSetting":
// commonMessageSettingController
// .model.serviceSetting,
// "tipSetting":
// val == true ? 1 : 0,
// "deviceUpgradeSetting":
// commonMessageSettingController
// .model
// .deviceUpgradeSetting,
// "deviceIssueSetting":
// commonMessageSettingController
// .model
// .deviceIssueSetting,
// };
// requestWithLog(
// logTitle: "更新消息推送状态",
// method: MyHttpMethod.put,
// queryUrl: queryUrl,
// data: data,
// onSuccess: (res) {
// _fetchDeviceList();
// commonMessageSettingController
// .updateAll();
// });
// },
// activeGradient: LinearGradient(
// colors: [
// themeController
// .currentColor.sc1,
// themeController.currentColor.sc2
// ],
// ),
// activeThumbColor: Colors.white,
// inactiveThumbColor:
// stringToColor("#A2A4A9"),
// inactiveColor:
// stringToColor("#161B28"),
// );
// }),
// ],
// ),
// // Text(
// // "绑定操作提示介绍".tr,
// // style: TextStyle(
// // color:
// // themeController.currentColor.sc4,
// // fontSize: AppConstants()
// // .normal_text_fontSize),
// // ),
// ].divide(SizedBox(
// height: 49.rpx,
// )),
// )),
// ),
// ),
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0, 21.rpx, 0, 0),
child: Container(
width: double.infinity,
constraints: BoxConstraints(
minHeight: 90.rpx,
),
decoration: BoxDecoration(
color: themeController.currentColor.sc5),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 15.rpx, 30.rpx, 15.rpx),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
"设备故障通知".tr,
style: TextStyle(
color: themeController
.currentColor.sc3,
fontSize: AppConstants()
.title_text_fontSize),
),
),
Obx(() {
return GradientSwitch(
value: commonMessageSettingController
.model.setting ==
1
? (commonMessageSettingController
.model
.deviceUpgradeSetting ==
1
? true
: false)
: false,
onChanged: (val) {
if (commonMessageSettingController
.model.setting ==
0) {
TopSlideNotification.show(
context,
text: "请先打开全部消息配置".tr,
textColor: themeController
.currentColor.sc9);
return;
}
String serviceAddress =
ServiceConstant
.service_address;
String serviceName =
ServiceConstant
.server_service;
String serviceApi =
ServiceConstant.user_setting;
String type =
"user_message_setting";
String queryUrl =
"${serviceAddress}${serviceName}${serviceApi}";
var data = {
"type": type,
"setting":
commonMessageSettingController
.model.setting,
"appSetting":
commonMessageSettingController
.model.appSetting,
"serviceSetting":
commonMessageSettingController
.model.serviceSetting,
"tipSetting":
commonMessageSettingController
.model.tipSetting,
"deviceUpgradeSetting":
val == true ? 1 : 0,
"deviceIssueSetting":
commonMessageSettingController
.model
.deviceIssueSetting,
};
requestWithLog(
logTitle: "更新消息推送状态",
method: MyHttpMethod.put,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
_fetchDeviceList();
commonMessageSettingController
.updateAll();
});
},
activeGradient: LinearGradient(
colors: [
themeController
.currentColor.sc1,
themeController.currentColor.sc2
],
),
activeThumbColor: Colors.white,
inactiveThumbColor:
stringToColor("#A2A4A9"),
inactiveColor:
stringToColor("#161B28"),
);
}),
],
),
// Text(
// "绑定操作提示介绍".tr,
// style: TextStyle(
// color:
// themeController.currentColor.sc4,
// fontSize: AppConstants()
// .normal_text_fontSize),
// ),
].divide(SizedBox(
height: 49.rpx,
)),
)),
),
),
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0, 21.rpx, 0, 0),
child: Container(
width: double.infinity,
constraints: BoxConstraints(
minHeight: 90.rpx,
),
decoration: BoxDecoration(
color: themeController.currentColor.sc5),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 15.rpx, 30.rpx, 15.rpx),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
"设备升级通知".tr,
style: TextStyle(
color: themeController
.currentColor.sc3,
fontSize: AppConstants()
.title_text_fontSize),
),
),
Obx(() {
return GradientSwitch(
value: commonMessageSettingController
.model.setting ==
1
? (commonMessageSettingController
.model
.deviceIssueSetting ==
1
? true
: false)
: false,
onChanged: (val) {
if (commonMessageSettingController
.model.setting ==
0) {
TopSlideNotification.show(
context,
text: "请先打开全部消息配置".tr,
textColor: themeController
.currentColor.sc9);
return;
}
String serviceAddress =
ServiceConstant
.service_address;
String serviceName =
ServiceConstant
.server_service;
String serviceApi =
ServiceConstant.user_setting;
String type =
"user_message_setting";
String queryUrl =
"${serviceAddress}${serviceName}${serviceApi}";
var data = {
"type": type,
"setting":
commonMessageSettingController
.model.setting,
"appSetting":
commonMessageSettingController
.model.appSetting,
"serviceSetting":
commonMessageSettingController
.model.serviceSetting,
"tipSetting":
commonMessageSettingController
.model.tipSetting,
"deviceUpgradeSetting":
commonMessageSettingController
.model
.deviceUpgradeSetting,
"deviceIssueSetting":
val == true ? 1 : 0,
};
requestWithLog(
logTitle: "更新消息推送状态",
method: MyHttpMethod.put,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
_fetchDeviceList();
commonMessageSettingController
.updateAll();
});
},
activeGradient: LinearGradient(
colors: [
themeController
.currentColor.sc1,
themeController.currentColor.sc2
],
),
activeThumbColor: Colors.white,
inactiveThumbColor:
stringToColor("#A2A4A9"),
inactiveColor:
stringToColor("#161B28"),
);
}),
],
),
// Text(
// "绑定操作提示介绍".tr,
// style: TextStyle(
// color:
// themeController.currentColor.sc4,
// fontSize: AppConstants()
// .normal_text_fontSize),
// ),
].divide(SizedBox(
height: 49.rpx,
)),
)),
),
),
],
),
),
),
),
),
),
),
),
);
}
}