YSInputView.dart 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import '../../tool/YSTools.dart';
  4. class YSInputView extends StatefulWidget {
  5. final Map item;
  6. final int length;
  7. const YSInputView({Key? key, required this.item, this.length = 100}) : super(key: key);
  8. @override
  9. YSInputViewState createState() => YSInputViewState();
  10. }
  11. class YSInputViewState extends State<YSInputView> {
  12. final TextEditingController _editingController = TextEditingController();
  13. @override
  14. void dispose() {
  15. _editingController.dispose();
  16. super.dispose();
  17. }
  18. @override
  19. Widget build(BuildContext context) {
  20. return Container(
  21. height: hsp(87),
  22. decoration: BoxDecoration(
  23. color: const Color(0xFF1A1C1F),
  24. border: Border.all(color: const Color(0xFF3E434E),width: hsp(1)),
  25. borderRadius: const BorderRadius.all(Radius.circular(3))
  26. ),
  27. padding: EdgeInsets.all(hsp(10)),
  28. child: Column(
  29. children: [
  30. SizedBox(
  31. height: hsp(50),
  32. child: CupertinoTextField(
  33. placeholderStyle: TextStyle(fontSize: zsp(14),color: ysValueColor),
  34. style: TextStyle(fontSize: zsp(14),color: ysValueColor),
  35. padding: const EdgeInsets.all(0),
  36. placeholder: '请输入${widget.item['title']}',
  37. decoration: const BoxDecoration(color: Colors.transparent),
  38. maxLines: 100,
  39. controller: _editingController,
  40. maxLength: widget.length,
  41. onChanged: (value){
  42. if(value.isNotEmpty){
  43. widget.item['value'] = value;
  44. }else{
  45. widget.item.remove('value');
  46. }
  47. setState(() {});
  48. },
  49. ),
  50. ),
  51. Container(
  52. height: hsp(15),
  53. alignment: Alignment.centerRight,
  54. child: Text('${_editingController.text.length}/${widget.length}',style: TextStyle(fontSize: zsp(14),color: const Color(0xFFACB5C5)),),
  55. )
  56. ],
  57. )
  58. );
  59. }
  60. }
  61. class YSInputView2 extends StatefulWidget {
  62. final Map item;
  63. final int length;
  64. final int height;
  65. final bool isEnable;
  66. const YSInputView2({Key? key, required this.item, this.length = 100, this.height = 80, this.isEnable = true}) : super(key: key);
  67. @override
  68. YSInputView2State createState() => YSInputView2State();
  69. }
  70. class YSInputView2State extends State<YSInputView2> {
  71. final TextEditingController _editingController = TextEditingController();
  72. @override
  73. void initState() {
  74. _editingController.text = widget.item['value']??'';
  75. super.initState();
  76. }
  77. @override
  78. void dispose() {
  79. _editingController.dispose();
  80. super.dispose();
  81. }
  82. @override
  83. Widget build(BuildContext context) {
  84. return Column(
  85. children: [
  86. SizedBox(
  87. height: hsp(widget.height),
  88. child: widget.isEnable?CupertinoTextField(
  89. placeholderStyle: TextStyle(fontSize: zsp(14),color: ysValueColor),
  90. style: TextStyle(fontSize: zsp(14),color: ysValueColor),
  91. padding: const EdgeInsets.all(0),
  92. placeholder: '请输入${widget.item['title']}',
  93. decoration: const BoxDecoration(color: Colors.transparent),
  94. maxLines: 100,
  95. controller: _editingController,
  96. maxLength: widget.length,
  97. onChanged: (value){
  98. if(value.isNotEmpty){
  99. widget.item['value'] = value;
  100. }else{
  101. widget.item.remove('value');
  102. }
  103. setState(() {});
  104. },
  105. ):Align(
  106. alignment: Alignment.topLeft,
  107. child: Text(_editingController.text,style: TextStyle(fontSize: zsp(14),color: ysValueColor),),
  108. )
  109. ),
  110. widget.isEnable?Container(
  111. height: hsp(20),
  112. alignment: Alignment.centerRight,
  113. child: Text('${_editingController.text.length}/${widget.length}',style: TextStyle(fontSize: zsp(14),color: const Color(0xFFACB5C5)),),
  114. ):Container(height: hsp(20))
  115. ],
  116. );
  117. }
  118. }
  119. class YSInputView3 extends StatefulWidget {
  120. final String title;
  121. final String value;
  122. final ValueSetter valueSetter;
  123. final bool isSec;
  124. const YSInputView3({Key? key, required this.title, required this.valueSetter, this.isSec = false, this.value = ''}) : super(key: key);
  125. @override
  126. YSInputView3State createState() => YSInputView3State();
  127. }
  128. class YSInputView3State extends State<YSInputView3> {
  129. bool _isSec = false;
  130. final TextEditingController _editingController = TextEditingController();
  131. @override
  132. void initState() {
  133. _editingController.text = widget.value;
  134. _isSec = widget.isSec;
  135. super.initState();
  136. }
  137. // @override
  138. // void didUpdateWidget(covariant YSInputView3 oldWidget) {
  139. // if(oldWidget.value!=widget.value){
  140. // _editingController.text = widget.value;
  141. // }
  142. // super.didUpdateWidget(oldWidget);
  143. // }
  144. @override
  145. Widget build(BuildContext context) {
  146. return Container(
  147. decoration: BoxDecoration(
  148. color: const Color(0xFF1A1C1F),
  149. border: Border.all(color: const Color(0xFF3E434E),width: hsp(1)),
  150. borderRadius: const BorderRadius.all(Radius.circular(3))
  151. ),
  152. padding: EdgeInsets.all(hsp(10)),
  153. child: Column(
  154. crossAxisAlignment: CrossAxisAlignment.start,
  155. children: [
  156. SizedBox(
  157. height: hsp(15),
  158. child: Text(widget.title,style: TextStyle(fontSize: zsp(11),color: const Color(0xFFACB5C5)),),
  159. ),
  160. SizedBox(
  161. height: hsp(30),
  162. child: CupertinoTextField(
  163. placeholderStyle: TextStyle(fontSize: zsp(14),color: ysValueColor),
  164. style: TextStyle(fontSize: zsp(14),color: ysValueColor),
  165. padding: const EdgeInsets.all(0),
  166. placeholder: '请输入${widget.title}',
  167. decoration: const BoxDecoration(color: Colors.transparent),
  168. controller: _editingController,
  169. onChanged: (value){
  170. setState(() {});
  171. widget.valueSetter(value);
  172. },
  173. obscureText: _isSec,
  174. suffix: Row(
  175. children: [
  176. Padding(
  177. padding: const EdgeInsets.only(left: 5,right: 5),
  178. child: widget.isSec?GestureDetector(
  179. onTap: (){
  180. _isSec = !_isSec;
  181. setState(() {});
  182. },
  183. child: Image.asset('images/${_isSec?'eye-slash':'eye'}.png',height: hsp(15),width: hsp(15),color: Colors.white,)
  184. ):Container(width: hsp(20),),
  185. ),
  186. if(_editingController.text.isNotEmpty)GestureDetector(
  187. onTap: (){
  188. _editingController.text = '';
  189. setState(() {});
  190. },
  191. child: Image.asset('images/tzh_clear.png',height: hsp(20),width: hsp(20),),
  192. )
  193. ],
  194. ),
  195. ),
  196. ),
  197. ],
  198. )
  199. );
  200. }
  201. }