YSWomanBody.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. import 'package:fl_chart/fl_chart.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  5. import 'package:flutterappfuyou/code/base/YSTools.dart';
  6. import 'YSAddBodyData.dart';
  7. import 'YSInputWidgetInfo.dart';
  8. class YSWomanBody extends StatefulWidget {
  9. @override
  10. _YSWomanBodyState createState() => _YSWomanBodyState();
  11. }
  12. class _YSWomanBodyState extends State<YSWomanBody> {
  13. List weights = [];
  14. List weightArray = [];
  15. PageController _page = PageController();
  16. int index = 0;
  17. @override
  18. void initState() {
  19. for(int i =0;i<60;i++){
  20. weightArray.add({'week':i+1});
  21. }
  22. Future.delayed(Duration(seconds: 0)).then((value){
  23. _getWomanBodyData();
  24. });
  25. super.initState();
  26. }
  27. @override
  28. Widget build(BuildContext context) {
  29. return Scaffold(
  30. body: SingleChildScrollView(
  31. child: Column(
  32. children: [
  33. Container(
  34. height: MediaQuery.of(context).padding.top+44,
  35. padding: EdgeInsets.only(left: 5,top: 20,right: 15),
  36. child: Row(
  37. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  38. children: [
  39. CupertinoButton(
  40. padding: EdgeInsets.all(0),
  41. child: Icon(Icons.keyboard_arrow_left,size: 30,color: Color(0xFF292929),),
  42. onPressed: (){
  43. Navigator.pop(context);
  44. },
  45. ),
  46. Text('体重管理',style: TextStyle(fontSize: 16,color: Color(0xFF292929),fontWeight: FontWeight.w600),),
  47. CupertinoButton(
  48. padding: EdgeInsets.all(0),
  49. child: Text('',style: TextStyle(fontSize: 14,color: Color(0xFFDB5278)),),//增重建议
  50. onPressed: (){
  51. return;
  52. Navigator.of(context).push(
  53. CupertinoPageRoute(
  54. builder: (context){
  55. return YSInputWidgetInfo();
  56. }
  57. )
  58. );
  59. },
  60. ),
  61. ],
  62. ),
  63. ),
  64. Stack(
  65. children: [
  66. Container(
  67. height: 150,
  68. width: MediaQuery.of(context).size.width,
  69. child: PageView(
  70. controller: _page,
  71. onPageChanged: (value){
  72. index = value;
  73. },
  74. children: weightArray.map((e) {
  75. return Stack(
  76. children: [
  77. GestureDetector(
  78. onTap: (){
  79. Navigator.of(context).push(
  80. CupertinoPageRoute(
  81. builder: (context){
  82. return YSAddBodyData(index: e['week'],);
  83. }
  84. )
  85. ).then((value){
  86. if(value!=null){
  87. _getWomanBodyData();
  88. }
  89. });
  90. },
  91. child: Container(
  92. margin: EdgeInsets.only(top: 13,bottom: 13,left: 75,right: 75),
  93. height: 124,
  94. width: MediaQuery.of(context).size.width-150,
  95. padding: EdgeInsets.all(15),
  96. decoration: BoxDecoration(
  97. borderRadius: BorderRadius.all(Radius.circular(20)),
  98. color: Color(0xFFEB6E91),
  99. ),
  100. child: e['weight']!=null?Column(
  101. crossAxisAlignment: CrossAxisAlignment.start,
  102. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  103. children: [
  104. Text('孕 ${e['week']} 周',style: TextStyle(fontSize: 12,color: Colors.white),),
  105. RichText(
  106. text: TextSpan(
  107. style: TextStyle(fontSize: 34,color: Colors.white,fontWeight: FontWeight.w600),
  108. children: [
  109. TextSpan(text: '${e['weight']}'),
  110. TextSpan(text: 'kg',style: TextStyle(fontSize: 12,fontWeight: FontWeight.normal))
  111. ]
  112. ),
  113. ),
  114. Row(
  115. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  116. children: [
  117. Text('',style: TextStyle(fontSize: 12,color: Colors.white),),//已增重: 50.0kg
  118. Image(height: 20,width: 20,image: AssetImage('lib/images/update.png'),)
  119. ],
  120. )
  121. ],
  122. ):Column(
  123. crossAxisAlignment: CrossAxisAlignment.start,
  124. children: [
  125. Text('孕 ${e['week']} 周',style: TextStyle(fontSize: 12,color: Colors.white),),
  126. Container(
  127. height: 70,
  128. alignment: Alignment.center,
  129. child: Icon(Icons.add,size: 60,color: Colors.white,),
  130. )
  131. ],
  132. ),
  133. ),
  134. ),
  135. ],
  136. );
  137. }).toList(),
  138. ),
  139. ),
  140. Container(
  141. height: 150,
  142. padding: EdgeInsets.only(left: 15,right: 15),
  143. child: Row(
  144. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  145. children: [
  146. GestureDetector(
  147. child: Icon(Icons.keyboard_arrow_left,size: 30,color: Color(0xFF808080),),
  148. onTap: (){
  149. _page.jumpToPage(index-1);
  150. },
  151. ),
  152. GestureDetector(
  153. child: Icon(Icons.keyboard_arrow_right,size: 30,color: Color(0xFF808080),),
  154. onTap: (){
  155. _page.jumpToPage(index+1);
  156. },
  157. ),
  158. ],
  159. ),
  160. )
  161. ],
  162. ),
  163. Text('',style: TextStyle(fontSize: 11,color: Color(0xFF808080)),),//孕前体重: 0.0kg
  164. Container(
  165. margin: EdgeInsets.only(top: 5,bottom: 15),
  166. child: Text('',style: TextStyle(fontSize: 11,color: Color(0xFF4D4D4D)),),//本周体重范围: 0.0kg
  167. ),
  168. Container(
  169. width: MediaQuery.of(context).size.width,
  170. height: 1.5,
  171. child: Image.asset('lib/images/line.png'),
  172. ),
  173. Container(
  174. child: Text('孕期体重增长曲线',style: TextStyle(fontSize: 14,color: Color(0xFF292929),fontWeight: FontWeight.w600),),
  175. margin: EdgeInsets.all(15),
  176. ),
  177. Container(
  178. padding: EdgeInsets.only(left: 50,right: 50),
  179. margin: EdgeInsets.only(bottom: 10),
  180. child: Row(
  181. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  182. children: [
  183. Container(
  184. child: Row(
  185. children: [
  186. // Image(height: 15,width: 15,image: AssetImage('lib/images/range.png'),),
  187. // Text(' 增重范围',style: TextStyle(fontSize: 11,color: Color(0xFF292929)),),
  188. ],
  189. ),
  190. ),
  191. Container(
  192. child: Row(
  193. children: [
  194. Image(height: 15,width: 15,image: AssetImage('lib/images/max.png'),),
  195. Text(' 我的体重(kg)',style: TextStyle(fontSize: 11,color: Color(0xFF292929)),),
  196. ],
  197. ),
  198. ),
  199. Container(
  200. child: Row(
  201. children: [
  202. // Image(height: 15,width: 15,image: AssetImage('lib/images/min.png'),),
  203. // Text(' 过重/过轻',style: TextStyle(fontSize: 11,color: Color(0xFF292929)),),
  204. ],
  205. ),
  206. )
  207. ],
  208. ),
  209. ),
  210. Container(
  211. margin: EdgeInsets.only(top: 5),
  212. child: weights.length>0?LineChartSample7(weight: weights,):Container(),
  213. )
  214. ],
  215. ),
  216. ),
  217. );
  218. }
  219. _getWomanBodyData() async{
  220. Map dict = await ysRequestHttp(context, requestType.post, 'phase/gestationList', {'type':'weight '});
  221. if(dict!=null){
  222. weights = dict['data']['weights'];
  223. // weights.sort((a, b) => (b.week).compareTo(a.week));
  224. for(int i=0;i<weights.length-1;i++){
  225. for(int j=0;j<weights.length-1-i;j++){
  226. if(weights[j]['week']>weights[j+1]['week']){
  227. Map temp = weights[j];
  228. weights[j] = weights[j+1];
  229. weights[j+1] = temp;
  230. }
  231. }
  232. }
  233. weights.forEach((element) {
  234. int index = weightArray.indexWhere((elementSub) => elementSub['week']==element['week']);
  235. weightArray[index] = element;
  236. });
  237. // LogUtil.d(weights);
  238. setState(() {});
  239. }
  240. }
  241. }
  242. class LineChartSample7 extends StatelessWidget {
  243. final List weight;
  244. const LineChartSample7({Key key, this.weight}) : super(key: key);
  245. @override
  246. Widget build(BuildContext context) {
  247. return SingleChildScrollView(
  248. padding: EdgeInsets.only(top: 5,left: 10,right: 10),
  249. scrollDirection: Axis.horizontal,
  250. child: SizedBox(
  251. width: (MediaQuery.of(context).size.width-40)/8*50,
  252. height: MediaQuery.of(context).size.height/100*50,
  253. child: LineChart(
  254. LineChartData(
  255. // borderData: FlBorderData(
  256. // border: Border(
  257. // left: BorderSide(width: 1,color: Colors.black),
  258. // right: BorderSide(width: 1,color: Colors.black),
  259. // bottom: BorderSide(width: 1,color: Colors.black)
  260. // )
  261. // ),
  262. lineTouchData: LineTouchData(enabled: false),
  263. lineBarsData: [
  264. LineChartBarData(
  265. spots: weight.map((f) {
  266. return FlSpot(
  267. double.parse('${f['week']}'),
  268. double.parse('${f['weight']}')
  269. );
  270. }).toList(),
  271. isCurved: true,
  272. barWidth: 2,
  273. colors: [
  274. Colors.green,
  275. ],
  276. dotData: FlDotData(
  277. show: true,
  278. ),
  279. ),
  280. ],
  281. titlesData: FlTitlesData(
  282. bottomTitles: SideTitles(
  283. showTitles: true,
  284. getTitles: (value) {
  285. return '第'+value.toInt().toString()+'周';
  286. },
  287. ),
  288. leftTitles: SideTitles(
  289. showTitles: true,
  290. getTitles: (value) {
  291. return value%10==0?value.toInt().toString()+'kg':'';
  292. },
  293. ),
  294. rightTitles: SideTitles(
  295. showTitles: true,
  296. getTitles: (value) {
  297. return value%10==0?value.toInt().toString()+'kg':'';
  298. },
  299. ),
  300. ),
  301. maxY: 120,
  302. maxX: 50,
  303. minX: 1,
  304. minY: 0,
  305. gridData: FlGridData(
  306. show: true,
  307. checkToShowHorizontalLine: (double value) {
  308. return value%10==0;
  309. },
  310. checkToShowVerticalLine: (double value) {
  311. return true;
  312. },
  313. drawVerticalLine: true,
  314. drawHorizontalLine: true,
  315. verticalInterval: 1,
  316. horizontalInterval: 1,
  317. ),
  318. ),
  319. ),
  320. ),
  321. );
  322. }
  323. }