YSChapterInputView.dart 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import '../../base/YSTools.dart';
  5. class YSChapterInputView extends StatefulWidget {
  6. final Map item;
  7. const YSChapterInputView({Key key, this.item}) : super(key: key);
  8. @override
  9. _YSChapterInputViewState createState() => _YSChapterInputViewState();
  10. }
  11. class _YSChapterInputViewState extends State<YSChapterInputView> {
  12. TextEditingController _editingController = TextEditingController();
  13. @override
  14. void dispose() {
  15. _editingController.dispose();
  16. super.dispose();
  17. }
  18. @override
  19. void initState() {
  20. _editingController.text = widget.item['value']??'';
  21. super.initState();
  22. }
  23. @override
  24. Widget build(BuildContext context) {
  25. bool isNumber = '${widget.item['title']}'.contains('数');
  26. return Column(
  27. crossAxisAlignment: CrossAxisAlignment.start,
  28. children: [
  29. Container(
  30. margin: EdgeInsets.only(bottom: 10),
  31. child: Text('${widget.item['title']}',style: TextStyle(fontSize: 14,color: Color(0xFF606266),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  32. ),
  33. Container(
  34. padding: EdgeInsets.only(left: 15,right: 15),
  35. height: 40,
  36. decoration: BoxDecoration(
  37. border: Border.all(color: Color(0xFFD7D7D7),width: 0.5),
  38. borderRadius: BorderRadius.all(Radius.circular(20))
  39. ),
  40. child: CupertinoTextField(
  41. style: TextStyle(fontSize: 14,color: Color(0xFF606266),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  42. placeholderStyle: TextStyle(fontSize: 14,color: Color(0xFF8A8A8A),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  43. placeholder: '请输入${widget.item['title']}',
  44. decoration: BoxDecoration(),
  45. prefix: Image(height: 15,width: 15,image: AssetImage('lib/images/${widget.item['image']}.png'),),
  46. inputFormatters: [if(isNumber)FilteringTextInputFormatter.digitsOnly],
  47. controller: _editingController,
  48. keyboardType: isNumber?TextInputType.number:TextInputType.text,
  49. onChanged: (value){
  50. if(value.isNotEmpty){
  51. widget.item['value'] = value;
  52. }else{
  53. widget.item.remove('value');
  54. }
  55. },
  56. )
  57. ),
  58. ],
  59. );
  60. }
  61. }
  62. class YSChapterChooseView extends StatefulWidget {
  63. final Map item;
  64. const YSChapterChooseView({Key key, this.item}) : super(key: key);
  65. @override
  66. _YSChapterChooseViewState createState() => _YSChapterChooseViewState();
  67. }
  68. class _YSChapterChooseViewState extends State<YSChapterChooseView> {
  69. @override
  70. Widget build(BuildContext context) {
  71. return Column(
  72. crossAxisAlignment: CrossAxisAlignment.start,
  73. children: [
  74. Container(
  75. margin: EdgeInsets.only(bottom: 10),
  76. child: Text('${widget.item['title']}',style: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  77. ),
  78. Container(
  79. height: 40,
  80. decoration: BoxDecoration(
  81. border: Border.all(color: Color(0xFFD7D7D7),width: 0.5),
  82. borderRadius: BorderRadius.all(Radius.circular(20))
  83. ),
  84. child: CupertinoButton(
  85. padding: EdgeInsets.only(left: 15,right: 15),
  86. child: Row(
  87. children: [
  88. Padding(
  89. padding: EdgeInsets.only(right: 5),
  90. child: Image(height: 15,width: 15,image: AssetImage('lib/images/${widget.item['image']}.png'),)
  91. ),
  92. Container(
  93. height: 40,
  94. alignment: Alignment.centerLeft,
  95. child: Text(widget.item['value']==null?'选择${widget.item['title']}':widget.item['value'],style: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),)
  96. )
  97. ],
  98. ),
  99. onPressed: (){
  100. FocusScope.of(context).unfocus();
  101. if('${widget.item['title']}'.contains('生日')||'${widget.item['title']}'.contains('预产期')){
  102. ysDatePicker(context, (value){
  103. setState(() {
  104. widget.item['value'] = value;
  105. });
  106. });
  107. }else if('${widget.item['title']}'.contains('性别')){
  108. ysShowCenterAlertView(context, YSChooseBabySexView(postSex: (value){
  109. widget.item['value'] = value;
  110. setState(() {});
  111. },));
  112. }
  113. },
  114. ),
  115. ),
  116. ],
  117. );
  118. }
  119. }
  120. class YSChooseBabySexView extends StatefulWidget {
  121. final ValueSetter postSex;
  122. const YSChooseBabySexView({Key key, this.postSex}) : super(key: key);
  123. @override
  124. _YSChooseBabySexViewState createState() => _YSChooseBabySexViewState();
  125. }
  126. class _YSChooseBabySexViewState extends State<YSChooseBabySexView> {
  127. @override
  128. Widget build(BuildContext context) {
  129. return Center(
  130. child: Container(
  131. width: ysWidth(context)-60,
  132. height: 150,
  133. decoration: BoxDecoration(
  134. borderRadius: BorderRadius.all(Radius.circular(10)),
  135. color: Colors.white,
  136. ),
  137. child: Column(
  138. children: [
  139. Container(
  140. height: 50,
  141. alignment: Alignment.centerLeft,
  142. padding: EdgeInsets.only(left: 20,right: 20),
  143. child: Text('选择性别',style: TextStyle(fontSize: 14,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.w600)),
  144. ),
  145. CupertinoButton(
  146. padding: EdgeInsets.all(0),
  147. child: Container(
  148. height: 50,
  149. alignment: Alignment.centerLeft,
  150. padding: EdgeInsets.only(left: 20,right: 20),
  151. child: Text('男',style: TextStyle(fontSize: 14,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  152. ),
  153. onPressed: (){
  154. Navigator.pop(context);
  155. widget.postSex('男');
  156. },
  157. ),
  158. CupertinoButton(
  159. padding: EdgeInsets.all(0),
  160. child: Container(
  161. height: 50,
  162. alignment: Alignment.centerLeft,
  163. padding: EdgeInsets.only(left: 20,right: 20),
  164. child: Text('女',style: TextStyle(fontSize: 14,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  165. ),
  166. onPressed: (){
  167. Navigator.pop(context);
  168. widget.postSex('女');
  169. },
  170. )
  171. ],
  172. ),
  173. ),
  174. );
  175. }
  176. }
  177. class YSSubmitView extends StatelessWidget {
  178. final VoidCallback callback;
  179. final String title;
  180. const YSSubmitView({Key key, this.callback, this.title = '确定'}) : super(key: key);
  181. @override
  182. Widget build(BuildContext context) {
  183. return GestureDetector(
  184. child: Container(
  185. height: 40,
  186. decoration: BoxDecoration(
  187. color: Color(0xFFEA6C8F),
  188. borderRadius: BorderRadius.all(Radius.circular(20))
  189. ),
  190. alignment: Alignment.center,
  191. child: Text(title,style: TextStyle(fontSize: 16,color: Colors.white,decoration: TextDecoration.none),),
  192. ),
  193. onTap: (){
  194. FocusScope.of(context).unfocus();
  195. callback();
  196. },
  197. );
  198. }
  199. }