import 'dart:async'; import 'package:ef/base/widget/flutterflow/FlutterFlowTheme.dart'; import 'package:ef/ef.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutterflow_ui/flutterflow_ui.dart'; import 'package:vbvs_app/common/util/FitTool.dart'; import 'package:vbvs_app/common/util/MyUtils.dart'; import 'package:vbvs_app/component/tool/CustomCard.dart'; import 'package:vbvs_app/controller/main_bottom/global_controller.dart'; import 'package:vbvs_app/controller/mh_controller/people_info_controller.dart'; import 'package:vbvs_app/pages/common/selectDialog.dart'; class PeopleInfoPage extends GetView { Map data; PeopleInfoPage({required this.data}); getLine() { return Divider( color: Color(0XFF929699), thickness: 0.5.rpx, height: 0, ); } PeopleInfoController controller = Get.put(PeopleInfoController()); @override Widget build(BuildContext context) { // 初始化只做一次 WidgetsBinding.instance.addPostFrameCallback((_) { controller.initData(data['mac']); }); return LayoutBuilder( builder: (context, boxConstraints) => 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( elevation: 0, surfaceTintColor: Colors.transparent, backgroundColor: Colors.transparent, automaticallyImplyLeading: false, iconTheme: IconThemeData(color: Colors.white), titleSpacing: 0, title: SizedBox( width: double.infinity, height: 180.rpx, child: Stack( alignment: Alignment.center, children: [ // 中间居中的标题 Text( '人员资料', textAlign: TextAlign.center, style: TextStyle( color: Colors.white, fontSize: 30.rpx, ), ), // 左侧图标 Positioned( left: 20.rpx, child: returnIconButtomNew, ), Positioned( right: 30.rpx, child: CustomCard( borderRadius: 16.rpx, gradientDirection: GradientDirection.vertical, onTap: () async { bool isValid = true; // 数据验证 for (int i = 0; i < controller.model.peopleList.length; i++) { var d = controller.model.peopleList[i]; String prefix = "人员信息${i == 0 ? "A" : "B"}:"; if (d['height'] != null && d['height'].toString().isNotEmpty && int.tryParse(d['height'].toString()) == null) { showToast("$prefix身高请输入数字"); isValid = false; break; } if (d['weight'] != null && d['weight'].toString().isNotEmpty && int.tryParse(d['weight'].toString()) == null) { showToast("$prefix体重请输入数字"); isValid = false; break; } if (d['tel'] != null && d['tel'].toString().isNotEmpty && !MyUtils.isValidPhoneNumber( d['tel'].toString())) { showToast("$prefix请输入正确的电话"); isValid = false; break; } if (d['contact'] != null && d['contact'].toString().isNotEmpty && !MyUtils.isValidPhoneNumber( d['contact'].toString())) { showToast("$prefix请输入正确的紧急联系人电话"); isValid = false; break; } } // 所有数据合法,开始保存 if (isValid) { for (var data in controller.model.peopleList) { try { await controller.savePeoples( data); // 注意:你这个方法名是 savePeoples,建议改成 savePerson showToast("保存成功(${data['mac']})", color: color_success); } catch (e) { print("保存失败:$e"); showToast("保存失败(${data['mac']})"); } } } }, colors: const [ Color(0xFFFCFCFC), Color(0xFFF8FAF9), Color(0XFFECF6F3), Color(0XFFD9F0E9), Color(0xFFCEECE3) ], child: Container( width: 120.rpx, height: 60.rpx, alignment: Alignment.center, // decoration: BoxDecoration( // borderRadius: BorderRadius.circular(5), // color: stringToColor("#182B7C"), // ), child: Text( "保存", style: FlutterFlowTheme.of(context) .bodyMedium .override( fontFamily: 'Readex Pro', color: Color(0XFF011D33), letterSpacing: 0, fontSize: 30.rpx, ), ), ), )) ], ), ), centerTitle: false, ), body: SafeArea( top: true, child: Container( padding: EdgeInsets.only(left: 30.rpx, right: 30.rpx), width: MediaQuery.sizeOf(context).width, height: MediaQuery.sizeOf(context).height * 1.123, // decoration: BoxDecoration( // color: Colors.transparent, // image: DecorationImage( // image: AssetImage("assets/images/background.png"), // fit: BoxFit.cover, // ), // ), child: SingleChildScrollView( child: Column( children: [ if (controller.model.peopleList.isNotEmpty) ...List.generate(controller.model.peopleList.length, (index) { final person = controller.model.peopleList[index]; String location_ = ''; // if ("${data["bindMacB"]}".length > 6 && // (person["direction"] == 1 || // person["direction"] == 2)) { // location_ = person["direction"] == 1 ? '左侧' : '右侧'; // } return Column( mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( margin: EdgeInsets.only( left: 18.rpx, top: index == 0 ? 30.rpx : 90.rpx, bottom: 20.rpx), child: Text( "人员资料${index == 0 ? "A" : "B"}", style: TextStyle( color: Colors.white, fontSize: 30.rpx), ), ), Container( child: Column( children: [ getLine(), Obx( () => Container( width: double.infinity, height: 90.rpx, margin: EdgeInsets.only( left: 40.rpx, right: 35.rpx), decoration: BoxDecoration(), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( '姓名', style: FlutterFlowTheme.of( context) .bodyMedium .override( fontFamily: 'Readex Pro', color: Color(0xFF9EA4B7), fontSize: 30.rpx, letterSpacing: 0, ), ), Container( width: 300.rpx, child: TextField( obscureText: false, textAlign: TextAlign.right, style: TextStyle( fontSize: 30.rpx, color: Colors.white), decoration: const InputDecoration( fillColor: Colors.transparent, filled: true, hintText: "请输入姓名", hintStyle: TextStyle( color: Colors.white), border: InputBorder.none, contentPadding: EdgeInsets.all(0)), onChanged: (value) { controller.model .peopleList[index] ["name"] = value; }, controller: controller.onReDraw( TextEditingController( text: controller.model .peopleList[ index] ["name"] ?? ""), (textEditingController) { textEditingController .text = controller.model .peopleList[index] ["name"] ?? ""; }, "people_name_$index"), ), ), ], ), ), ), getLine(), Obx( () => Container( margin: EdgeInsets.only( left: 40.rpx, right: 35.rpx), width: double.infinity, height: 90.rpx, decoration: BoxDecoration(), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( '性别', style: FlutterFlowTheme.of( context) .bodyMedium .override( fontFamily: 'Readex Pro', color: Color(0xFF9EA4B7), fontSize: 30.rpx, letterSpacing: 0, ), ), InkWell( onTap: () { // 触摸收起键盘 FocusScope.of(context) .requestFocus(FocusNode()); Future.delayed( const Duration( milliseconds: 250), () { // 延迟执行的代码 showOneSelectionDialog( context, arr: ["女", "男"], checkIndex: controller .model .peopleList[ index] ['gender'] == "女" ? 0 : 1, checkChange: (sindex) { controller.model.peopleList[ index]['gender'] = sindex; // 👈 保存为 0 / 1 controller.updateAll(); print("gender $sindex"); }).then((d) { // Timer(Duration.zero, () { // FocusScope.of(context).unfocus(); // }); }); }); }, child: Row( mainAxisSize: MainAxisSize.max, children: [ Container( width: 200.rpx, child: Text( '${controller.model.peopleList[index]['gender'] == 1 ? '男' : '女'}', textAlign: TextAlign.right, style: FlutterFlowTheme .of(context) .bodyMedium .override( fontFamily: 'Readex Pro', color: Colors.white, fontSize: 30.rpx, letterSpacing: 0, ), ), ), SizedBox( width: 16.rpx, ), Icon( Icons.expand_more, color: Colors.white, size: 48.rpx, ), ], ), ), ], ), ), ), getLine(), Container( width: double.infinity, height: 90.rpx, margin: EdgeInsets.only( left: 40.rpx, right: 35.rpx), decoration: BoxDecoration(), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( '身高(cm)', style: FlutterFlowTheme.of(context) .bodyMedium .override( fontFamily: 'Readex Pro', color: Color(0xFF9EA4B7), fontSize: 30.rpx, letterSpacing: 0, ), ), InkWell( onTap: () { FocusScope.of(context).unfocus(); Future.delayed( const Duration( milliseconds: 250), () { showHeightPickerDialog( context, initialHeight: controller .model .peopleList[index] ['height'] ?? 170, onConfirm: (int selectedHeight) { controller.model.peopleList[ index]['height'] = selectedHeight .toString(); controller.updateAll(); print( "身高: $selectedHeight cm"); }, ); }); }, child: Row( children: [ Text( controller.model.peopleList[ index] ['height'] != null ? "${controller.model.peopleList[index]['height']} cm" : '', style: FlutterFlowTheme.of( context) .bodyMedium .override( fontFamily: 'Readex Pro', color: Colors.white, fontSize: 30.rpx, ), ), SizedBox(width: 16.rpx), Icon(Icons.expand_more, color: Colors.white, size: 48.rpx), ], ), ), ], ), ), getLine(), Container( width: double.infinity, height: 90.rpx, margin: EdgeInsets.only( left: 40.rpx, right: 35.rpx), decoration: BoxDecoration(), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( '体重(kg)', style: FlutterFlowTheme.of(context) .bodyMedium .override( fontFamily: 'Readex Pro', color: Color(0xFF9EA4B7), fontSize: 30.rpx, letterSpacing: 0, ), ), InkWell( onTap: () { FocusScope.of(context).unfocus(); Future.delayed( const Duration( milliseconds: 250), () { showWeightPickerDialog( context, initialWeight: controller .model .peopleList[index] ['weight'] ?? "", onConfirm: (int selectedWeight) { controller.model.peopleList[ index]['weight'] = selectedWeight .toString(); // ✅ 转成字符串 controller.updateAll(); print( "体重: $selectedWeight kg"); }, ); }); }, child: Row( children: [ Text( controller.model.peopleList[ index] ['weight'] != null ? "${controller.model.peopleList[index]['weight']} kg" : '', style: FlutterFlowTheme.of( context) .bodyMedium .override( fontFamily: 'Readex Pro', color: Colors.white, fontSize: 30.rpx, ), ), SizedBox(width: 16.rpx), Icon(Icons.expand_more, color: Colors.white, size: 48.rpx), ], ), ), ], ), ), getLine(), Obx( () => Container( width: double.infinity, height: 90.rpx, margin: EdgeInsets.only( left: 40.rpx, right: 35.rpx), decoration: BoxDecoration(), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( '生日', style: FlutterFlowTheme.of( context) .bodyMedium .override( fontFamily: 'Readex Pro', color: Color(0xFF9EA4B7), fontSize: 30.rpx, letterSpacing: 0, ), ), InkWell( onTap: () { // 触摸收起键盘 FocusScope.of(context) .requestFocus(FocusNode()); Future.delayed( const Duration( milliseconds: 250), () { // 延迟执行的代码 showDateSelectionDialog( context, checkDate: controller .model .peopleList[index] ['birthday'] is DateTime ? controller.model .peopleList[index] ['birthday'] : DateTime.tryParse( controller.model.peopleList[index]['birthday'] ?? '') ?? DateTime.now(), checkChange: (DateTime d) { controller.model .peopleList[index] ['birthday'] = d; controller.updateAll(); print("$d"); }).then((d) { // Timer(Duration.zero, () { // FocusScope.of(context).unfocus(); // }); }); }); }, child: Row( mainAxisSize: MainAxisSize.max, children: [ Container( constraints: BoxConstraints( minWidth: 200.rpx), child: Text( controller.model.peopleList[ index][ 'birthday'] != null ? time_08_Formatter_pattern( controller.model .peopleList[ index] ['birthday'], "yyyy年MM月dd日") : '', textAlign: TextAlign.right, style: FlutterFlowTheme .of(context) .bodyMedium .override( fontFamily: 'Readex Pro', color: Colors.white, fontSize: 30.rpx, letterSpacing: 0, ), ), ), SizedBox( width: 16.rpx, ), Icon( Icons.expand_more, color: Colors.white, size: 48.rpx, ), ], ), ), ], ), ), ), getLine(), Container( width: double.infinity, height: 90.rpx, margin: EdgeInsets.only( left: 40.rpx, right: 35.rpx), decoration: BoxDecoration(), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( '联系人', style: FlutterFlowTheme.of(context) .bodyMedium .override( fontFamily: 'Readex Pro', color: Color(0xFF9EA4B7), fontSize: 30.rpx, letterSpacing: 0, ), ), Container( width: 300.rpx, child: TextField( obscureText: false, keyboardType: TextInputType.number, textInputAction: TextInputAction.done, textAlign: TextAlign.right, style: TextStyle( fontSize: 30.rpx, color: Colors.white), decoration: InputDecoration( fillColor: Colors.transparent, filled: true, hintText: "请输入联系人", hintStyle: TextStyle( color: Colors.white), border: InputBorder.none, contentPadding: EdgeInsets.all(0)), onChanged: (value) { controller .model.peopleList[index] ['contact'] = value; controller.updateAll(); }, controller: controller.onReDraw( TextEditingController( text: controller.model .peopleList[ index] ['contact'] ?? ""), (textEditingController) { textEditingController .text = controller.model .peopleList[index] ['contact'] ?? ""; }, "contact_$index"), ), ), ], ), ), getLine(), ], ), ) ], ); }), SizedBox( height: 100.rpx, ), ], )), ), ), ), )), ); } String time_08_Formatter_pattern(dynamic date, String pattern) { if (date == null || date.toString().isEmpty) return "-"; try { String normalized = date.toString().replaceAll("/", "-"); DateTime dt = DateTime.parse(normalized); return DateFormat(pattern).format(dt); } catch (e) { return "-"; } } }