YSPeriod.dart 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  5. import 'base/YSBase.dart';
  6. class YSPeriod extends StatefulWidget {
  7. @override
  8. _YSPeriodState createState() => _YSPeriodState();
  9. }
  10. class _YSPeriodState extends State<YSPeriod> {
  11. TextEditingController _time = TextEditingController();
  12. TextEditingController _period = TextEditingController();
  13. _getChapterData() async{
  14. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'chapter/info', {'category_id':1});
  15. if(dict!=null){
  16. Map data = dict['data']??{};
  17. _time.text = '${data['duration']??''}';
  18. _period.text = '${data['cycle']??''}';
  19. setState(() {});
  20. }
  21. }
  22. @override
  23. void initState() {
  24. Future.delayed(Duration(seconds: 0)).then((value) {
  25. _getChapterData();
  26. });
  27. super.initState();
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return YSBase(
  32. ystitle: '经期设置',
  33. yschild: SingleChildScrollView(
  34. child: Column(
  35. children: [
  36. Container(
  37. width: MediaQuery.of(context).size.width,
  38. margin: EdgeInsets.only(left: 40,top: 25,bottom: 10),
  39. child: Text('月经周期天数',style: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  40. ),
  41. Container(
  42. width: MediaQuery.of(context).size.width-50,
  43. margin: EdgeInsets.only(bottom: 10),
  44. padding: EdgeInsets.only(left: 10,right: 10),
  45. height: 40,
  46. decoration: BoxDecoration(
  47. border: Border.all(color: Color(0xFFD7D7D7),width: 0.5),
  48. borderRadius: BorderRadius.all(Radius.circular(20))
  49. ),
  50. child: CupertinoTextField(
  51. style: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  52. placeholderStyle: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  53. placeholder: '请输入周期天数',
  54. decoration: BoxDecoration(),
  55. prefix: Image(height: 15,width: 15,image: AssetImage('lib/images/time.png'),),
  56. inputFormatters: [FilteringTextInputFormatter.digitsOnly],
  57. controller: _period,
  58. keyboardType: TextInputType.number,
  59. )
  60. ),
  61. Container(
  62. width: MediaQuery.of(context).size.width,
  63. margin: EdgeInsets.only(left: 40,top: 10,bottom: 10),
  64. child: Text('月经持续天数',style: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  65. ),
  66. Container(
  67. width: MediaQuery.of(context).size.width-50,
  68. margin: EdgeInsets.only(bottom: 80),
  69. padding: EdgeInsets.only(left: 10,right: 10),
  70. height: 40,
  71. decoration: BoxDecoration(
  72. border: Border.all(color: Color(0xFFD7D7D7),width: 0.5),
  73. borderRadius: BorderRadius.all(Radius.circular(20))
  74. ),
  75. child: CupertinoTextField(
  76. style: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  77. placeholderStyle: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  78. placeholder: '请输入持续天数',
  79. inputFormatters: [FilteringTextInputFormatter.digitsOnly],
  80. decoration: BoxDecoration(),
  81. prefix: Image(height: 15,width: 15,image: AssetImage('lib/images/water.png'),),
  82. controller: _time,
  83. keyboardType: TextInputType.number,
  84. )
  85. ),
  86. CupertinoButton(
  87. padding: EdgeInsets.all(0),
  88. child: Container(
  89. width: MediaQuery.of(context).size.width-150,
  90. height: 40,
  91. decoration: BoxDecoration(
  92. color: Color(0xFFEA6C8F),
  93. borderRadius: BorderRadius.all(Radius.circular(20))
  94. ),
  95. alignment: Alignment.center,
  96. child: Text('提交',style: TextStyle(fontSize: 16,color: Colors.white,decoration: TextDecoration.none),),
  97. ),
  98. onPressed: (){
  99. FocusScope.of(context).unfocus();
  100. _postPeriodData();
  101. },
  102. )
  103. ],
  104. ),
  105. ),
  106. );
  107. }
  108. _postPeriodData() async{
  109. if(_period.text.isEmpty){
  110. ysFlutterToast(context, '请输入周期时间');
  111. return;
  112. }
  113. if(int.parse(_period.text)>51){
  114. ysFlutterToast(context, '周期时间过长');
  115. return;
  116. }
  117. if(_time.text.isEmpty){
  118. ysFlutterToast(context, '请输入持续时间');
  119. return;
  120. }
  121. if(int.parse(_time.text)>51){
  122. ysFlutterToast(context, '持续时间过长');
  123. return;
  124. }
  125. Map dict = await ysRequestHttp(context,requestType.put, 'motherhood/period', {'cycle':_period.text,'duration':_time.text});
  126. if(dict!=null){
  127. Navigator.of(context).pop('完成');
  128. }
  129. }
  130. }