YSDueDate.dart 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  4. import 'base/YSBase.dart';
  5. import 'base/YSTools.dart';
  6. class YSDueDate extends StatefulWidget {
  7. final String dueDate;
  8. const YSDueDate({Key key, this.dueDate}) : super(key: key);
  9. @override
  10. _YSDueDateState createState() => _YSDueDateState();
  11. }
  12. class _YSDueDateState extends State<YSDueDate> {
  13. String dueDate;
  14. @override
  15. void initState() {
  16. // dueDate = widget.dueDate;
  17. Future.delayed(Duration(seconds: 0)).then((value) {
  18. _getChapterData();
  19. });
  20. super.initState();
  21. }
  22. _getChapterData() async{
  23. Map param = Map();
  24. param['category_id'] = 2;
  25. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'chapter/info', param);
  26. if(dict!=null){
  27. setState(() {
  28. dueDate = dict['data']['expected_time'];
  29. });
  30. }
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. return YSBase(
  35. ystitle: '设置预产期',
  36. yschild: SingleChildScrollView(
  37. child: Column(
  38. children: [
  39. Container(
  40. height: 45,
  41. width: MediaQuery.of(context).size.width,
  42. padding: EdgeInsets.all(15),
  43. child: Text('请输入产检时医生告知的预产期,也可以使用“计算预产期”',style: TextStyle(fontSize: 12,color: Color(0xFF8E1B3C),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  44. ),
  45. Container(
  46. width: MediaQuery.of(context).size.width,
  47. height: 1.5,
  48. child: Image.asset('lib/images/line.png'),
  49. ),
  50. Container(
  51. width: MediaQuery.of(context).size.width,
  52. margin: EdgeInsets.only(left: 40,top: 25,bottom: 10),
  53. child: Text('预产期',style: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  54. ),
  55. CupertinoButton(
  56. padding: EdgeInsets.all(0),
  57. child: Container(
  58. width: MediaQuery.of(context).size.width-50,
  59. margin: EdgeInsets.only(bottom: 20),
  60. padding: EdgeInsets.only(left: 15,right: 15),
  61. height: 40,
  62. decoration: BoxDecoration(
  63. border: Border.all(color: Color(0xFFD7D7D7),width: 0.5),
  64. borderRadius: BorderRadius.all(Radius.circular(20))
  65. ),
  66. alignment: Alignment.centerLeft,
  67. child: Text(dueDate==null?'选择预产期':dueDate,style: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),)
  68. ),
  69. onPressed: (){
  70. ysDatePicker(context, (value){
  71. setState(() {
  72. dueDate = value;
  73. });
  74. });
  75. },
  76. ),
  77. CupertinoButton(
  78. padding: EdgeInsets.all(0),
  79. child: Container(
  80. width: MediaQuery.of(context).size.width-50,
  81. height: 20,
  82. margin: EdgeInsets.only(bottom: 100),
  83. alignment: Alignment.centerRight,
  84. child: Container(
  85. height: 20,
  86. width: 100,
  87. child: Row(
  88. children: [
  89. Image(height: 15,width: 15,image: AssetImage('lib/images/calculte.png'),),
  90. Text(' 计算预产期',style: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),)
  91. ],
  92. ),
  93. )
  94. ),
  95. onPressed: (){
  96. String dateStr = '';
  97. // if(dueDate!=null){
  98. // dateStr = dueDate;
  99. // }
  100. showDialog(context: context,builder: (context){
  101. return Dialog(
  102. backgroundColor: Colors.transparent,
  103. child: StatefulBuilder(
  104. builder: (context,setYSState){
  105. return Container(
  106. width: MediaQuery.of(context).size.width,
  107. padding: EdgeInsets.all(15),
  108. height: 150,
  109. decoration: BoxDecoration(
  110. color: Colors.white,
  111. borderRadius: BorderRadius.all(Radius.circular(10))
  112. ),
  113. child: Column(
  114. crossAxisAlignment: CrossAxisAlignment.start,
  115. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  116. children: [
  117. Text('计算预产期',style: TextStyle(fontSize: 14,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  118. CupertinoButton(
  119. padding: EdgeInsets.all(0),
  120. child: Container(
  121. height: 30,
  122. width: MediaQuery.of(context).size.width-30,
  123. child: Text(dateStr.isNotEmpty?dateStr:'请选择末次月经时间进行计算',style: TextStyle(fontSize: 13,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  124. decoration: BoxDecoration(
  125. border: Border(bottom: BorderSide(width: 0.5,color: Color(0xFFD7D7D7)))
  126. ),
  127. ),
  128. onPressed: (){
  129. ysDatePicker(context, (value){
  130. setYSState(() {
  131. dateStr = value;
  132. });
  133. },lastDate: DateTime.now().subtract(Duration(days: 1)),initDate: DateTime.now().subtract(Duration(days: 1)));
  134. },
  135. ),
  136. Row(
  137. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  138. children: [
  139. Container(),
  140. Row(
  141. children: [
  142. CupertinoButton(
  143. padding: EdgeInsets.all(0),
  144. child: Text('取消',style: TextStyle(fontSize: 13,color: Color(0xFF8E1B3C),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  145. onPressed: (){
  146. Navigator.pop(context);
  147. },
  148. ),
  149. CupertinoButton(
  150. padding: EdgeInsets.all(0),
  151. child: Text('计算',style: TextStyle(fontSize: 13,color: Color(0xFF8E1B3C),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  152. onPressed: () async{
  153. if(dateStr.isEmpty){
  154. ysFlutterToast(context, '请选择时间后进行计算');
  155. return;
  156. }
  157. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'phase/dueDateQuery', {'date':dateStr});
  158. if(dict!=null){
  159. Navigator.pop(context);
  160. dueDate = dict['data']['data'];
  161. setState(() {});
  162. }
  163. },
  164. )
  165. ],
  166. )
  167. ],
  168. )
  169. ],
  170. ),
  171. );
  172. },
  173. ),
  174. );
  175. });
  176. },
  177. ),
  178. CupertinoButton(
  179. padding: EdgeInsets.all(0),
  180. child: Container(
  181. width: MediaQuery.of(context).size.width-150,
  182. height: 40,
  183. decoration: BoxDecoration(
  184. color: Color(0xFFEA6C8F),
  185. borderRadius: BorderRadius.all(Radius.circular(20))
  186. ),
  187. alignment: Alignment.center,
  188. child: Text('提交',style: TextStyle(fontSize: 16,color: Colors.white,decoration: TextDecoration.none),),
  189. ),
  190. onPressed: () async{
  191. if(dueDate==null){
  192. ysFlutterToast(context, '请选择预产期');
  193. return;
  194. }
  195. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'phase/dueDate', {'expected_time':dueDate});
  196. if(dict!=null){
  197. Navigator.pop(context,'完成');
  198. }
  199. },
  200. )
  201. ],
  202. ),
  203. ),
  204. );
  205. }
  206. }