import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../widgets/buttons/custom_elevated_button.dart'; import 'bottom_bar.dart'; import 'number_stepper.dart'; class DetlEditPage extends StatefulWidget { final data; final config; final double? maxCount; const DetlEditPage({super.key, required this.data, required this.config, this.maxCount}); @override State createState() => _DetlEditPageState(); } class _DetlEditPageState extends State { @override void initState() { super.initState(); widget.config.forEach((item) { widget.data.forEach((key, value) { if (key == item['propName']) { item['value'] = value; } }); }); } void _back() { widget.config.forEach((item) { final String propName = item['propName']; final newValue = item['value']; widget.data[propName] = newValue; }); Get.back(result: widget.data); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('编辑明细'), ), body: Center( child: ListView( children: List.generate(widget.config.length, (index) { var title = widget.config[index]['title']; var value = widget.config[index]['value']; var type = widget.config[index]['type']; var propName = widget.config[index]['propName']; var isShow = widget.config[index]['isShow']; if (value == null) { value = ''; } return ListItem( title: title, value: value, type: type, propName: propName, isShow: isShow, ); }), ), ), bottomNavigationBar: BottomBar( children: [ CEBtn(title: "完成", type: Type.second, onPressed: _back), ], ), ); } Widget ListItem({ required String title, required String propName, required value, required String type, required bool isShow, }) { if (!isShow) { return SizedBox.shrink(); } else { return Container( color: Colors.white, child: Container( padding: const EdgeInsets.only(top: 10, bottom: 10,right: 10), margin: const EdgeInsets.only(left: 10), constraints: BoxConstraints(minHeight: 50), decoration: BoxDecoration( color: Colors.white, border: Border(bottom: BorderSide(color: Colors.grey[300]!)), ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('$title:',style: const TextStyle(fontSize: 16,fontWeight: FontWeight.bold)), SizedBox(width: 10), CustomText(text: value, type: type, propName: propName,title: title), ] ), ), ); } } Widget CustomText({ required text, required String type, required String propName, required String title, }) { switch (type) { case 'textFiled': return Expanded( child: Container( constraints: BoxConstraints(maxHeight: double.infinity), child: InkWell( onTap: () { Get.toNamed('/custom_editor_page', arguments: {'title': title, 'text': text, 'propName': propName} )?.then((result) { print('value: $result'); setState(() { widget.config.forEach((item) { if (item['propName'] == result['propName']) { item['value'] = result['text']; } }); }); }); }, child: Row( children: [ Expanded(child: Text(text ?? '--'),), Icon(Icons.arrow_forward_ios_rounded, size: 16, color: Colors.grey), ], ), ) ), ); case 'number': return Expanded(child: Center(child: NumberStepper(defaultValue: text,maxValue: widget.maxCount,minValue: 0,onValueChanged: (value) { widget.config.forEach((item) { if (item['propName'] == propName) { setState(() { item['value'] = value; }); } }); },))); default: return Expanded(child: Text((text != null && text.toString().isNotEmpty) ? text.toString() : '--',softWrap: true, overflow: TextOverflow.ellipsis, maxLines: 3)); } } }