import 'package:ef/ef.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:flutterflow_ui/flutterflow_ui.dart'; import 'package:vbvs_app/common/color/appFontsize.dart'; import 'package:vbvs_app/common/color/app_uri_status.dart'; import 'package:vbvs_app/common/util/FitTool.dart'; import 'package:vbvs_app/common/util/MyUtils.dart'; import 'package:vbvs_app/component/tool/TopSlideNotification.dart'; import 'package:vbvs_app/controller/mh_controller/message_controller.dart'; import 'package:vbvs_app/controller/mh_controller/mhdevice_share_controller.dart'; import 'package:vbvs_app/model/api_response.dart'; import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart'; import 'package:vbvs_app/pages/mh_page/test/WebviewTestModel.dart'; class MessageDetailPage extends StatefulWidget { final data; const MessageDetailPage({super.key, required this.data}); @override _MessageDetailPageState createState() => _MessageDetailPageState(); } class _MessageDetailPageState extends State { MHDeviceShareController controller = Get.find(); MhMessageController messageController = Get.find(); RxInt status = 0.obs; @override Widget build(BuildContext context) { status.value = widget.data['status']; var messageInfo = widget.data; return LayoutBuilder( builder: (context, boxConstraints) => GestureDetector( // onTap: () => FocusScope.of(context).unfocus(),, child: Container( decoration: const BoxDecoration( image: DecorationImage( image: AssetImage('assets/images/new_background.png'), // 本地图片 fit: BoxFit.fill, // 填满整个 Container ), ), child: Scaffold( appBar: AppBar( backgroundColor: Colors.transparent, automaticallyImplyLeading: false, iconTheme: IconThemeData(color: themeController.currentColor.sc3), titleSpacing: 0, title: SizedBox( width: double.infinity, height: 180.rpx, child: Stack( alignment: Alignment.center, children: [ // 中间居中的标题 Text( '消息详情'.tr, textAlign: TextAlign.center, style: TextStyle( color: Colors.white, fontSize: 30.rpx, ), ), // 左侧图标 Positioned( left: 0.rpx, child: returnIconButtomNew(), ), ], ), ), actions: const [], centerTitle: false, ), backgroundColor: Colors.transparent, body: SafeArea( top: true, child: Padding( padding: EdgeInsets.only(top: 30.rpx), child: Column( children: [ Padding( padding: EdgeInsets.only(left: 30.rpx, right: 30.rpx), child: Container( decoration: BoxDecoration( color: Color(0XFF003058), borderRadius: BorderRadius.circular(16.rpx), ), child: Padding( padding: EdgeInsets.only( left: 30.rpx, top: 20.rpx, bottom: 20.rpx), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: double.infinity, constraints: BoxConstraints( minHeight: 66.rpx), child: Align( alignment: AlignmentDirectional(-1, 0), child: Text( "${messageInfo['data']['title']}", style: TextStyle( fontFamily: 'Inter', fontSize: 30.rpx, letterSpacing: 0.0, color: themeController .currentColor.sc3, ), ), ), ), Row( mainAxisSize: MainAxisSize.max, children: [ Container( constraints: BoxConstraints( minWidth: 30.rpx, maxWidth: 140.rpx), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: messageInfo['data'] ['val'] .map((mapItem) => _buildInfoItem( context, mapItem['k'] ?? '')) .toList(), ), ), Container( constraints: BoxConstraints( minWidth: 30.rpx), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: messageInfo['data'] ['val'] .map((mapItem) => _buildValueItem( context, mapItem['v'] ?? '')) .toList(), ), ), ].divide(SizedBox(width: 0.rpx)), ), ], ))), ), const Spacer(), bottomIcon(context) ], )), ), ), ), )); } Container bottomIcon(BuildContext context) { return Container( height: 120.rpx, decoration: BoxDecoration( color: Color(0xFF003058), ), width: double.infinity, child: TextButton( onPressed: () async { if (widget.data['status'] == 1) { ApiResponse apiResponse = await controller .confirmShare(widget.data['data']['shareCode']); if (apiResponse.code == HttpStatusCodes.ok) { TopSlideNotification.show(context, text: apiResponse.msg!, textColor: Color(0xFF00C1AA)); messageController.getMessageList(widget.data['type']); messageController.updateAll(); //todo 更新设备列表 MHTHomeController homeController = Get.find(); //更新设备列表 homeController.getPersonList(); //请求绑定设备列表 // homeController.getSleepReport(); homeController.getDeviceNum().then((apiResponse) { if (apiResponse.code != HttpStatusCodes.ok) { TopSlideNotification.show( Get.context!, text: apiResponse.msg!, textColor: themeController.currentColor.sc9, ); } }); homeController.getDeviceList(group: 'room').then((apiResponse) { if (apiResponse.code != HttpStatusCodes.ok) { try { WebviewTestController webviewTestController = Get.find(); webviewTestController.web.jsbridge?.dart.alterDevice(); } catch (e) { ef.log("[h5]通知列表更新报错:$e"); } TopSlideNotification.show( Get.context!, text: apiResponse.msg!, textColor: themeController.currentColor.sc9, ); } else { //请求睡眠报告 // deviceController.getSleepReport(); } }); WidgetsBinding.instance.addPostFrameCallback((_) { if (homeController.homeSleepDays.value.isNotEmpty) { homeController.selectedDayIndex.value = homeController.homeSleepDays.value.length - 1; } }); await homeController.getPersonList(); } else { TopSlideNotification.show(context, text: apiResponse.msg!, textColor: Color(0XFFFF7159)); messageController.getMessageList(widget.data['type']); messageController.updateAll(); } } }, child: Obx(() => Text( getStatusText(status.value), style: TextStyle( fontFamily: 'Readex Pro', color: status.value == 1 ? Colors.white : Color(0xFF929699), fontSize: 26.rpx, letterSpacing: 0, ), ))), ); } Widget _buildInfoItem(BuildContext context, String label) { return Container( constraints: BoxConstraints( minHeight: 62.rpx, ), child: Align( alignment: AlignmentDirectional(-1, 0), child: Text( overflow: TextOverflow.ellipsis, maxLines: 1, label.tr, style: TextStyle( fontFamily: 'Inter', fontSize: 26.rpx, letterSpacing: 0.0, color: themeController.currentColor.sc4, ), ), ), ); } Widget _buildValueItem(BuildContext context, value) { return Container( constraints: BoxConstraints( minHeight: 62.rpx, ), child: Align( alignment: AlignmentDirectional(-1, 0), child: Text( overflow: TextOverflow.ellipsis, maxLines: 1, "${value}", style: TextStyle( fontFamily: 'Inter', fontSize: 26.rpx, letterSpacing: 0.0, color: themeController.currentColor.sc3, ), ), ), ); } String getStatusText(int status) { switch (status) { case 1: return '同意'.tr; case 2: return '已同意'.tr; case 3: return '已过期'.tr; default: return '未知状态'.tr; } } }