350 lines
16 KiB
Dart
350 lines
16 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:ef/ef.dart';
|
|
import 'package:flutter/material.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/tool/CustomCard.dart';
|
|
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
|
import 'package:vbvs_app/controller/mh_controller/device_list_controller.dart';
|
|
import 'package:vbvs_app/pages/mh_page/bluetooth.dart';
|
|
import 'package:vbvs_app/pages/mh_page/device/controller/mht_bluetooth_controller.dart';
|
|
import 'package:vbvs_app/pages/mh_page/test/WebviewTestModel.dart';
|
|
|
|
class EditBedPage extends StatefulWidget {
|
|
final Map data;
|
|
|
|
EditBedPage({
|
|
Key? key,
|
|
required this.data,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_EditBedPageState createState() => _EditBedPageState();
|
|
}
|
|
|
|
BoxConstraints? bodysize;
|
|
|
|
class _EditBedPageState extends State<EditBedPage> {
|
|
late Map<String, dynamic> editedData;
|
|
late TextEditingController _nameController; //名称文本输入框
|
|
DeviceListController deviceListController = Get.find();
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
editedData = Map.from(widget.data); // 创建副本
|
|
_nameController = TextEditingController(text: editedData['name']);
|
|
|
|
// 添加监听器
|
|
_nameController.addListener(() {
|
|
setState(() {}); // 每次文字变化刷新UI
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_nameController.dispose(); // 记得释放Controller
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return LayoutBuilder(builder: (context, cc) {
|
|
bodysize = cc;
|
|
return GestureDetector(
|
|
onTap: () {
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
|
},
|
|
child: Container(
|
|
decoration: const BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage('assets/images/new_background.png'), // 本地图片
|
|
fit: BoxFit.fill, // 填满整个 Container
|
|
),
|
|
),
|
|
child: Scaffold(
|
|
backgroundColor: Colors.transparent,
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
iconTheme: const IconThemeData(color: Colors.white),
|
|
automaticallyImplyLeading: false,
|
|
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(),
|
|
),
|
|
if (widget.data != null &&
|
|
(widget.data['isNextStep'] != null &&
|
|
widget.data['isNextStep'] == true))
|
|
Positioned(
|
|
right: 30.rpx,
|
|
child: CustomCard(
|
|
borderRadius: 16.rpx,
|
|
gradientDirection: GradientDirection.vertical,
|
|
onTap: () async {
|
|
final MHTBlueToothController bluetoothController =
|
|
Get.find();
|
|
final device =
|
|
bluetoothController.currentFullDevice;
|
|
if (editedData['name'] == null ||
|
|
editedData['name'] == '') {
|
|
if (device!.type == 2) {
|
|
editedData['name'] = '智能电动床'.tr;
|
|
} else {
|
|
editedData['name'] = '律动智能床垫'.tr;
|
|
}
|
|
}
|
|
String serviceAddress =
|
|
ServiceConstant.service_address;
|
|
String serviceName = ServiceConstant.server_service;
|
|
String serviceApi = ServiceConstant.device_show;
|
|
String queryUrl =
|
|
"$serviceAddress$serviceName$serviceApi";
|
|
await requestWithLog(
|
|
logTitle: "更新设备信息".tr,
|
|
method: MyHttpMethod.put,
|
|
queryUrl: queryUrl,
|
|
data: {
|
|
"id": editedData["_id"],
|
|
"name": editedData["name"],
|
|
},
|
|
onSuccess: (res) {
|
|
TopSlideNotification.show(context,
|
|
text: "修改名称成功".tr);
|
|
deviceListController.getDeviceList();
|
|
Map data = {};
|
|
data['_id'] = device!.deviceID;
|
|
data['isNextStep'] = true;
|
|
Get.toNamed("/roomPickerPage", arguments: data);
|
|
},
|
|
);
|
|
},
|
|
colors: const [
|
|
Color(0xFFFCFCFC),
|
|
Color(0xFFF8FAF9),
|
|
Color(0XFFECF6F3),
|
|
Color(0XFFD9F0E9),
|
|
Color(0xFFCEECE3)
|
|
],
|
|
child: Container(
|
|
width: 120.rpx,
|
|
height: 60.rpx,
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
"下一步".tr,
|
|
style: TextStyle(
|
|
fontFamily: 'Readex Pro',
|
|
color: Color(0XFF011D33),
|
|
letterSpacing: 0,
|
|
fontSize: 30.rpx,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
centerTitle: false,
|
|
),
|
|
body: SafeArea(
|
|
top: true,
|
|
child: Padding(
|
|
padding: EdgeInsets.only(top: 40.rpx),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Container(
|
|
width: bodysize!.maxHeight * 1,
|
|
height: bodysize!.maxHeight * 0.335,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Container(
|
|
child:
|
|
Image.asset('assets/images/bed_name.png'),
|
|
width: bodysize!.maxWidth * 0.69,
|
|
height: 193.rpx,
|
|
),
|
|
Padding(
|
|
padding:
|
|
EdgeInsets.symmetric(horizontal: 60.rpx),
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
height: bodysize!.maxHeight * 0.076,
|
|
decoration: const BoxDecoration(
|
|
border: Border(
|
|
bottom: BorderSide(
|
|
color: Color(0xFF929699), // 灰色底部线
|
|
width: 0.5, // 根据需要设置宽度
|
|
),
|
|
),
|
|
),
|
|
child: Stack(
|
|
children: [
|
|
TextFormField(
|
|
controller: _nameController,
|
|
obscureText: false,
|
|
onChanged: (val) {
|
|
editedData['name'] = val;
|
|
},
|
|
textAlign: TextAlign.center,
|
|
textAlignVertical:
|
|
TextAlignVertical.center,
|
|
decoration: InputDecoration(
|
|
hintText: "请输入设备的名称".tr,
|
|
contentPadding:
|
|
const EdgeInsets.symmetric(
|
|
vertical: 0, horizontal: 10),
|
|
labelStyle: TextStyle(
|
|
fontFamily: 'Readex Pro',
|
|
letterSpacing: 0,
|
|
fontSize: 36.rpx,
|
|
color: Colors.white,
|
|
),
|
|
hintStyle: TextStyle(
|
|
fontFamily: 'Readex Pro',
|
|
letterSpacing: 0,
|
|
fontSize: 36.rpx,
|
|
color: const Color(0xFF929699),
|
|
),
|
|
enabledBorder: UnderlineInputBorder(
|
|
borderSide: BorderSide.none,
|
|
borderRadius:
|
|
BorderRadius.circular(8),
|
|
),
|
|
focusedBorder: UnderlineInputBorder(
|
|
borderSide: BorderSide.none,
|
|
borderRadius:
|
|
BorderRadius.circular(8),
|
|
),
|
|
errorBorder: UnderlineInputBorder(
|
|
borderSide: BorderSide.none,
|
|
borderRadius:
|
|
BorderRadius.circular(8),
|
|
),
|
|
focusedErrorBorder:
|
|
UnderlineInputBorder(
|
|
borderSide: BorderSide.none,
|
|
borderRadius:
|
|
BorderRadius.circular(8),
|
|
),
|
|
),
|
|
style: TextStyle(
|
|
fontFamily: 'Readex Pro',
|
|
fontSize: 36.rpx,
|
|
color: Colors.white,
|
|
letterSpacing: 0,
|
|
),
|
|
cursorColor: Colors.white,
|
|
// ✅ 允许横向滚动防止溢出:
|
|
keyboardType: TextInputType.text,
|
|
maxLines: 1,
|
|
scrollPadding: EdgeInsets.zero,
|
|
enableInteractiveSelection: true,
|
|
expands: false,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
if (widget.data['isNextStep'] == null ||
|
|
widget.data['isNextStep'] == false)
|
|
Padding(
|
|
padding: EdgeInsets.only(
|
|
left: 30.rpx, right: 30.rpx, bottom: 85.rpx),
|
|
child: CustomCard(
|
|
borderRadius: 16.rpx,
|
|
gradientDirection: GradientDirection.vertical,
|
|
onTap: () async {
|
|
String serviceAddress =
|
|
ServiceConstant.service_address;
|
|
String serviceName =
|
|
ServiceConstant.server_service;
|
|
String serviceApi =
|
|
ServiceConstant.device_show;
|
|
String queryUrl =
|
|
"$serviceAddress$serviceName$serviceApi";
|
|
if (editedData['name'] == null ||
|
|
editedData['name'] == '') {
|
|
if (editedData['device_type'] == 2) {
|
|
editedData['name'] = '智能电动床'.tr;
|
|
} else {
|
|
editedData['name'] = '律动智能床垫'.tr;
|
|
}
|
|
}
|
|
await requestWithLog(
|
|
logTitle: "更新设备信息".tr,
|
|
method: MyHttpMethod.put,
|
|
queryUrl: queryUrl,
|
|
data: {
|
|
"id": editedData["_id"],
|
|
"name": editedData["name"],
|
|
},
|
|
onSuccess: (res) {
|
|
TopSlideNotification.show(context,
|
|
text: "修改名称成功".tr);
|
|
deviceListController.getDeviceList();
|
|
try {
|
|
WebviewTestController
|
|
webviewTestController = Get.find();
|
|
webviewTestController.web.jsbridge?.dart
|
|
.alterDevice();
|
|
} catch (e) {
|
|
ef.log("[h5]通知列表更新错误:$e");
|
|
}
|
|
Get.back(result: editedData);
|
|
},
|
|
);
|
|
},
|
|
colors: const [
|
|
Color(0xFFFCFCFC),
|
|
Color(0xFFF8FAF9),
|
|
Color(0XFFECF6F3),
|
|
Color(0XFFD9F0E9),
|
|
Color(0xFFCEECE3)
|
|
],
|
|
child: Container(
|
|
width: double.infinity,
|
|
height: 90.rpx,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(6),
|
|
),
|
|
child: Text("完成".tr,
|
|
style: TextStyle(
|
|
color: const Color(0xFF003058),
|
|
fontSize: 26.rpx)),
|
|
),
|
|
))
|
|
],
|
|
))),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
}
|