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

286 lines
12 KiB
Dart
Raw Permalink 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:flutter/services.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/controller/message/common_message_setting_controller.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
class MHTCommonMessageSettingPage extends StatefulWidget {
MHTCommonMessageSettingPage({super.key});
@override
State<MHTCommonMessageSettingPage> createState() =>
_CommonMessageSettingPageState();
}
class _CommonMessageSettingPageState
extends State<MHTCommonMessageSettingPage> {
final ThemeController themeController = Get.find();
CommonMessageSettingController commonMessageSettingController = Get.find();
@override
void initState() {
super.initState();
commonMessageSettingController.getAppSleepNotify();
_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: "查询用户消息配置11",
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: "查询用户消息配置12",
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('assets/images/new_background.png'), // 本地图片
fit: BoxFit.fill,
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
systemOverlayStyle: SystemUiOverlayStyle(
statusBarColor: Colors.transparent, // 状态栏背景色
statusBarIconBrightness: Brightness.light, // 图标颜色Android
statusBarBrightness: Brightness.light, // 图标颜色iOS
),
backgroundColor: Colors.transparent,
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.sleepReportSetting ==
1
? true
: false,
onChanged: (val) async {
// String serviceAddress =
// ServiceConstant.service_address;
// String serviceName =
// ServiceConstant.server_service;
// String serviceApi = ServiceConstant
// .app_system_push_message;
// 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();
// });
await commonMessageSettingController
.updateSleepNotify(val);
await commonMessageSettingController
.getAppSleepNotify();
commonMessageSettingController
.updateAll();
},
activeGradient: LinearGradient(
colors: [
themeController.currentColor.sc1,
themeController.currentColor.sc2
],
),
activeThumbColor: Colors.white,
inactiveThumbColor:
stringToColor("#A2A4A9"),
inactiveColor: stringToColor("#161B28"),
);
}),
],
),
),
),
),
],
),
),
),
),
),
),
),
),
);
}
}