YSHome.dart 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:flutterappfuyou/code/YSAddChapter.dart';
  6. import 'package:flutterappfuyou/code/YSAskQuestion.dart';
  7. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  8. import 'package:flutterappfuyou/code/base/YSTools.dart';
  9. import 'package:flutterappfuyou/code/version2/YSUrlPage.dart';
  10. import 'package:flutterappfuyou/code/version2/YSVersionView.dart';
  11. import 'package:flutterappfuyou/code/version2/view/YSDoctorListView.dart';
  12. import 'package:flutterappfuyou/code/version2/view/YSWikiListView.dart';
  13. import 'package:package_info/package_info.dart';
  14. import 'YSChapters.dart';
  15. import 'YSChildBody.dart';
  16. import 'YSDiary.dart';
  17. import 'YSDoctor.dart';
  18. import 'YSDueDate.dart';
  19. import 'YSInformation.dart';
  20. import 'YSMore.dart';
  21. import 'YSPeriod.dart';
  22. import 'YSQuestion.dart';
  23. import 'YSRecord.dart';
  24. import 'YSWomanBody.dart';
  25. import 'package:shared_preferences/shared_preferences.dart';
  26. class YSHome extends StatefulWidget {
  27. @override
  28. State<StatefulWidget> createState() => _YSHomeState();
  29. }
  30. class _YSHomeState extends State<YSHome> {
  31. int chapter;
  32. bool isBoy = true;
  33. ScrollController _scroll = ScrollController();
  34. int selectedIndex = 0;
  35. int pageIndex = 0;
  36. String message = '';
  37. PageController _page = PageController();
  38. Map _info;
  39. List _function = [];
  40. List _doctors = [];
  41. List _wiki = [];
  42. bool _isPeriod = false;
  43. bool _isRoom = false;
  44. ScrollController _pageScroll = ScrollController();
  45. bool _isScroll = true;
  46. @override
  47. void initState() {
  48. Future.delayed(Duration(seconds: 0)).then((value) {
  49. _getUserData();
  50. getVersionData(context);
  51. toPage2(context);
  52. });
  53. Future<SharedPreferences> _prefer = SharedPreferences.getInstance();
  54. _prefer.then((value){
  55. chapter = value.getInt('chapters')??0;
  56. _getChapterData(chapter+1, value.getInt('childId')??0);
  57. });
  58. super.initState();
  59. }
  60. @override
  61. Widget build(BuildContext context){
  62. return AnnotatedRegion<SystemUiOverlayStyle>(
  63. value: SystemUiOverlayStyle.light,
  64. child: Scaffold(
  65. backgroundColor: Color(0xFFF5F3F0),
  66. body: chapter==null?Container(
  67. height: ysHeight(context),
  68. width: ysWidth(context),
  69. color: Colors.white,
  70. ):RefreshIndicator(
  71. onRefresh: _refresh,
  72. child: SingleChildScrollView(
  73. controller: _pageScroll,
  74. child: Container(
  75. color: Color(0xFFF5F3F0),
  76. child: Stack(
  77. children: [
  78. Container(
  79. width: MediaQuery.of(context).size.width,
  80. height: 204,
  81. color: Colors.white,
  82. child: Image(
  83. image: AssetImage(chapter==0?'lib/images/beiyunbg.png':chapter==1?'lib/images/yunchanbg.png':isBoy?'lib/images/babybg.png':'lib/images/babybg2.png'),
  84. fit: BoxFit.fill,
  85. )
  86. ),
  87. Container(
  88. width: 100,
  89. height: 20,
  90. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+10,left: MediaQuery.of(context).size.width/2-50),
  91. child: Text(chapter==0?'备孕篇':chapter==1?'孕产篇':'儿童篇',style: TextStyle(color: Colors.white,fontSize: 16,decoration: TextDecoration.none,fontWeight: FontWeight.normal),textAlign: TextAlign.center,),
  92. ),
  93. Container(
  94. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+10,left: MediaQuery.of(context).size.width-80),
  95. width: 70,
  96. height: 20,
  97. child: CupertinoButton(
  98. padding: EdgeInsets.all(0),
  99. child: Text('选择篇章',style: TextStyle(color: Colors.white,fontSize: 13,decoration: TextDecoration.none,fontWeight: FontWeight.normal),textAlign: TextAlign.center,),
  100. onPressed: (){
  101. Navigator.of(context,rootNavigator: true).push(
  102. CupertinoPageRoute(
  103. builder: (context){
  104. return YSChapters();
  105. }
  106. )
  107. ).then((value){
  108. if(value!=null){//
  109. _getChapterData(value['chapters'], value['child']);
  110. // _postChapterChooseData(value['chapters'],childId: value['child']);
  111. }
  112. });
  113. },
  114. ),
  115. ),
  116. Container(
  117. margin: EdgeInsets.only(left: chapter==0?10:chapter==1?0:35,top: chapter==0?MediaQuery.of(context).padding.top+50:chapter==1?
  118. MediaQuery.of(context).padding.top+35:MediaQuery.of(context).padding.top+75),
  119. height: chapter==0?120:chapter==1?150:66,
  120. width: chapter==0?120:chapter==1?150:66,
  121. decoration: BoxDecoration(
  122. color: chapter==0?Colors.transparent:chapter==1?Colors.transparent:Colors.white,
  123. borderRadius: BorderRadius.all(Radius.circular(33))
  124. ),
  125. child: GestureDetector(
  126. child: Image.asset(chapter==0?'lib/images/calendar.png':chapter==1?'lib/images/woman.png':'lib/images/baby.png'),
  127. onTap: (){
  128. if(chapter==0){
  129. Navigator.of(context,rootNavigator: true).push(
  130. CupertinoPageRoute(
  131. builder: (context){
  132. return YSRecord();
  133. }
  134. )
  135. );
  136. }
  137. },
  138. ),
  139. ),
  140. if (chapter==0) Container(
  141. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+70,left: 130),
  142. height: 80,
  143. width: MediaQuery.of(context).size.width-140,
  144. child: Column(
  145. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  146. crossAxisAlignment: CrossAxisAlignment.start,
  147. children: [
  148. Text('快来记录经期吧',style: TextStyle(color: Colors.white,fontSize: 12,decoration: TextDecoration.none,fontWeight: FontWeight.normal),textAlign: TextAlign.left,),
  149. Text(_isPeriod?'例假中':'未在经期',style: TextStyle(color: Colors.white,fontSize: 22,decoration: TextDecoration.none,fontWeight: FontWeight.normal),textAlign: TextAlign.left),
  150. Container(
  151. height: 20,
  152. child: Row(
  153. crossAxisAlignment: CrossAxisAlignment.start,
  154. children: [
  155. Container(height: 20,child: Text('周期:${_info==null?0:_info['cycle']}天',style: TextStyle(color: Colors.white,fontSize: 12,decoration: TextDecoration.none,fontWeight: FontWeight.normal)),alignment: Alignment.centerLeft,),
  156. CupertinoButton(
  157. padding: EdgeInsets.all(0),
  158. child: Image(height: 20,width: 20,image: AssetImage('lib/images/edit.png'),),
  159. onPressed: (){
  160. Navigator.of(context,rootNavigator: true).push(
  161. CupertinoPageRoute(
  162. builder: (context){
  163. return YSPeriod();
  164. }
  165. )
  166. ).then((value){
  167. if(value!=null){
  168. _getChapterData(1, 0);
  169. }
  170. });
  171. },
  172. ),
  173. ],
  174. ),
  175. )
  176. ],
  177. ),
  178. ) else chapter==1?Container(
  179. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+70,left: 130),
  180. height: 80,
  181. width: MediaQuery.of(context).size.width-140,
  182. child: Column(
  183. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  184. crossAxisAlignment: CrossAxisAlignment.start,
  185. children: [
  186. if(_info!=null)Text('距离宝宝出生还有',style: TextStyle(color: Colors.white,fontSize: 12,decoration: TextDecoration.none,fontWeight: FontWeight.normal),textAlign: TextAlign.left,),
  187. RichText(
  188. text: TextSpan(
  189. style: TextStyle(color: Colors.white,fontSize: 22,decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  190. children: [
  191. if(_info!=null)TextSpan(text:'${_info==null||_info['diff_in_day']>-1?0:(_info['diff_in_day']).abs()}'),
  192. TextSpan(text:'天',style: TextStyle(fontSize: 12)),
  193. ]
  194. ),
  195. ),
  196. //Text('100天',style: TextStyle(color: Colors.white,fontSize: 22,decoration: TextDecoration.none,fontWeight: FontWeight.normal),textAlign: TextAlign.left),
  197. Container(
  198. height: 20,
  199. child: Row(
  200. crossAxisAlignment: CrossAxisAlignment.start,
  201. children: [
  202. Container(height: 20, child: Text('设置预产期',style: TextStyle(color: Colors.white,fontSize: 12,decoration: TextDecoration.none,fontWeight: FontWeight.normal)),alignment: Alignment.centerLeft,),
  203. CupertinoButton(
  204. padding: EdgeInsets.all(0),
  205. child: Image(height: 20,width: 20,image: AssetImage('lib/images/edit.png'),),
  206. onPressed: (){
  207. Navigator.of(context,rootNavigator: true).push(
  208. CupertinoPageRoute(
  209. builder: (context){
  210. return YSDueDate(dueDate: _info['expected_time'],);
  211. }
  212. )
  213. ).then((value) {
  214. if(value!=null){
  215. _getChapterData(chapter+1, null);
  216. }
  217. });
  218. },
  219. )
  220. ],
  221. ),
  222. ),
  223. //Text('记录于${_info==null?0:_info['pregnancy_time']}',style: TextStyle(color: Colors.white,fontSize: 12,decoration: TextDecoration.none,fontWeight: FontWeight.normal),textAlign: TextAlign.left),
  224. ],
  225. ),
  226. ):Container(
  227. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+65,left: 130),
  228. height: 80,
  229. width: MediaQuery.of(context).size.width-140,
  230. child: Column(
  231. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  232. crossAxisAlignment: CrossAxisAlignment.start,
  233. children: [
  234. Text('${_info==null?0:_info['name']}',style: TextStyle(color: Colors.white,fontSize: 18,decoration: TextDecoration.none,fontWeight: FontWeight.normal),textAlign: TextAlign.left,),
  235. Container(
  236. height: 20,
  237. child: Row(
  238. crossAxisAlignment: CrossAxisAlignment.start,
  239. children: [
  240. Container(height: 20, child: Text('体重:${(_info!=null&&_info['weight']!=null)?_info['weight']:''}kg 身高:${(_info!=null&&_info['height']!=null)?_info['height']:''}cm ',
  241. style: TextStyle(color: Colors.white,fontSize: 12,decoration: TextDecoration.none,fontWeight: FontWeight.normal),textAlign: TextAlign.left),alignment: Alignment.centerLeft,),
  242. CupertinoButton(
  243. padding: EdgeInsets.all(0),
  244. child: Image(
  245. height: 20,
  246. width: 20,
  247. image: AssetImage('lib/images/edit.png'),
  248. ),
  249. onPressed: (){
  250. Navigator.of(context,rootNavigator: true).push(
  251. MaterialPageRoute(
  252. builder: (context){
  253. return YSChildBody();
  254. }
  255. )
  256. ).then((value) async{
  257. SharedPreferences _prefer = await SharedPreferences.getInstance();
  258. _getChapterData(chapter+1, _prefer.getInt('childId')??0);
  259. });
  260. },
  261. )
  262. ],
  263. ),
  264. ),
  265. Text('出生日期:${_info==null?0:_info['birthday']}',style: TextStyle(color: Colors.white,fontSize: 12,decoration: TextDecoration.none,fontWeight: FontWeight.normal),textAlign: TextAlign.left),
  266. ],
  267. ),
  268. ),
  269. Container(
  270. margin: EdgeInsets.only(top: 200),
  271. child: Column(
  272. children: [
  273. Container(
  274. decoration: BoxDecoration(
  275. borderRadius: BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10)),
  276. color: Colors.white,
  277. ),
  278. height: 50,
  279. child: chapter==0?Row(
  280. children: [
  281. Container(
  282. width: MediaQuery.of(context).size.width/2-0.25,
  283. child: Row(
  284. mainAxisAlignment: MainAxisAlignment.center,
  285. children: [
  286. Text('大姨妈来了',style: TextStyle(color: Color(0xFF7F3344),fontSize: 13,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  287. CupertinoButton(
  288. padding: EdgeInsets.all(0),
  289. onPressed: (){
  290. _isPeriod==false?_postPeriodData(1):_deletePeriodData(1);
  291. },
  292. child: Container(
  293. height: 18,
  294. width: 30,
  295. margin: EdgeInsets.only(left: 10),
  296. child: Image.asset(_isPeriod==true?'lib/images/sliderOn.png':'lib/images/sliderOff.png'),
  297. ),
  298. )
  299. ],
  300. ),
  301. ),
  302. Container(
  303. height: 30,
  304. color: Color(0xFFE5E1E1),
  305. width: 0.5,
  306. ),
  307. Container(
  308. width: MediaQuery.of(context).size.width/2-0.25,
  309. child: Row(
  310. mainAxisAlignment: MainAxisAlignment.center,
  311. children: [
  312. Text('房事',style: TextStyle(color: Color(0xFF7F3344),fontSize: 13,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  313. CupertinoButton(
  314. padding: EdgeInsets.all(0),
  315. onPressed: (){
  316. if(_isPeriod&&_isRoom==false){
  317. ysFlutterToast(context, '月经中不能同房');
  318. return;
  319. }
  320. _isRoom==false?_postPeriodData(2):_deletePeriodData(2);
  321. },
  322. child: Container(
  323. height: 18,
  324. width: 30,
  325. margin: EdgeInsets.only(left: 10),
  326. child: Image.asset(_isRoom==true?'lib/images/sliderOn.png':'lib/images/sliderOff.png'),
  327. ),
  328. )
  329. ],
  330. ),
  331. ),
  332. ],
  333. ):chapter==1?Row(
  334. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  335. children: [
  336. // CupertinoButton(
  337. // padding: EdgeInsets.all(0),
  338. // child: Icon(Icons.keyboard_arrow_left,size: 20,color: Color(0xFFDDBBC5),),
  339. // onPressed: (){
  340. // _scroll.jumpTo(_scroll.offset-60);
  341. // selectedIndex = (_scroll.offset+(MediaQuery.of(context).size.width)/2)~/60;
  342. // _getMessageData(chapter+1, selectedIndex,false);
  343. // },
  344. // ),
  345. Container(
  346. height: 35,
  347. width: MediaQuery.of(context).size.width-150,
  348. child: NotificationListener(
  349. onNotification: (value){
  350. if(value.runtimeType==ScrollEndNotification){
  351. if(_isScroll==false){
  352. int value = (_scroll.offset+(MediaQuery.of(context).size.width-150)/2)~/60;
  353. _getMessageData(chapter+1, value,false);
  354. }
  355. }
  356. return true;
  357. },
  358. child: ListView.builder(
  359. itemBuilder: (context,index){
  360. return GestureDetector(
  361. onTap: (){
  362. _getMessageData(chapter+1, index+1,false);
  363. },
  364. child: Container(
  365. color: Colors.white,
  366. width: 60,
  367. alignment: Alignment.center,
  368. child: Column(
  369. children: [
  370. Container(
  371. // child: index==5?Image.asset('lib/images/today.png'):null,
  372. width: 20,
  373. height: 10,
  374. margin: EdgeInsets.only(left: 35),//+1
  375. ),
  376. Text((index~/7).toInt().toString()+'周+'+(index%7+1).toString(),style: TextStyle(color: selectedIndex==index?Color(0xFF8E1B3C):Color(0xFFDDBBC5),
  377. fontSize: selectedIndex==index?16:12,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  378. ],
  379. )
  380. ),
  381. );
  382. },
  383. itemCount: 280,
  384. scrollDirection: Axis.horizontal,
  385. controller: _scroll,
  386. ),
  387. ),
  388. ),
  389. // CupertinoButton(
  390. // padding: EdgeInsets.all(0),
  391. // child: Icon(Icons.keyboard_arrow_right,size: 20,color: Color(0xFFDDBBC5),),
  392. // onPressed: (){
  393. // _scroll.jumpTo(_scroll.offset+60);
  394. // selectedIndex = (_scroll.offset+(MediaQuery.of(context).size.width)/2)~/60;
  395. // _getMessageData(chapter+1, selectedIndex,false);
  396. // },
  397. // ),
  398. ],
  399. ):Row(
  400. children: [
  401. if(_info!=null)Container(
  402. width: MediaQuery.of(context).size.width/2-0.25,
  403. child: Text('今天是${_info['name']}出生的第${_info['diff_in_day']}天',style: TextStyle(color: Color(0xFF7F3344),fontSize: 12,decoration: TextDecoration.none,fontWeight: FontWeight.normal),textAlign: TextAlign.center,),
  404. ),
  405. Container(
  406. height: 30,
  407. color: Color(0xFFE5E1E1),
  408. width: 0.5,
  409. ),
  410. Container(
  411. width: MediaQuery.of(context).size.width/2-0.25,
  412. child: CupertinoButton(
  413. padding: EdgeInsets.all(0),
  414. child: Container(
  415. width: 120,
  416. child: Row(
  417. crossAxisAlignment: CrossAxisAlignment.center,
  418. children: [
  419. Image(height: 20,width: 20,image: AssetImage('lib/images/babyInfo.png'),),
  420. Text(' 查看宝宝资料',style: TextStyle(color: Color(0xFF7F3344),fontSize: 12,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  421. ],
  422. ),
  423. ),
  424. onPressed: (){
  425. Navigator.of(context,rootNavigator: true).push(
  426. CupertinoPageRoute(
  427. builder: (context){
  428. return YSAddChapter(isEdit: true,);
  429. }
  430. )
  431. ).then((value) async{
  432. if(value!=null){
  433. SharedPreferences _prefer = await SharedPreferences.getInstance();
  434. _getChapterData(chapter+1, _prefer.getInt('childId')??0);
  435. }
  436. });
  437. },
  438. ),
  439. ),
  440. ],
  441. ),
  442. ),
  443. chapter==0?Container():Container(
  444. width: MediaQuery.of(context).size.width-10,
  445. padding: EdgeInsets.all(10),
  446. decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.all(Radius.circular(6))),
  447. margin: EdgeInsets.only(top: 5),
  448. child: message.isEmpty?Row(
  449. children: [
  450. Container(
  451. margin: EdgeInsets.only(left: 30,right: 30),
  452. height: 50,
  453. width: 80,
  454. child: Image.asset('lib/images/noMsg.png'),
  455. ),
  456. Text('您的消息会在这里展示',style: TextStyle(color: Color(0xFFBCBCBC),fontSize: 12,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  457. ],
  458. ):Text(message,style: TextStyle(color: Color(0xFFBCBCBC),fontSize: 12,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  459. ),
  460. chapter>1?Container():Container(
  461. width: MediaQuery.of(context).size.width-10,
  462. height: 100,
  463. decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.all(Radius.circular(6))),
  464. margin: EdgeInsets.only(top: 5),
  465. child: Container(
  466. height: 82,
  467. child: ListView.builder(
  468. scrollDirection: Axis.horizontal,
  469. itemCount: _function.length>4?4:_function.length,
  470. itemBuilder: (context,index){
  471. return GestureDetector(
  472. onTap: (){
  473. Navigator.of(context,rootNavigator: true).push(
  474. CupertinoPageRoute(
  475. builder: (context){
  476. if(_function.length>4&&index==3){
  477. return YSMore();
  478. }else if(_function[index]['value']=='PregnancyDiary'){
  479. return YSDiary();
  480. }else if(_function[index]['value']=='PregnancyBody'){
  481. return YSWomanBody();
  482. }else if(_function[index]['value']=='MotherhoodDiary'){
  483. return YSDiary();
  484. }else if(_function[index]['value']=='ChildBody'){
  485. return YSChildBody();
  486. }else if(_function[index]['value']=='ChildDiary'){
  487. return YSDiary();
  488. }else if('${_function[index]['value']}'.contains('http')==true){
  489. return YSUrlPage(url: _function[index]['value'],title: _function[index]['name']);
  490. }else{
  491. return YSMore();
  492. }
  493. }
  494. )
  495. );
  496. },
  497. child: Container(
  498. height: 82,
  499. padding: EdgeInsets.only(top: 10,bottom: 10),
  500. width: (MediaQuery.of(context).size.width-10)/4,
  501. child: Column(
  502. mainAxisAlignment: MainAxisAlignment.spaceAround,
  503. children: [
  504. Image(image:_function.length>4&&index==3?AssetImage('lib/images/more.png'):NetworkImage('${_function[index]['img']}'),height: 36,width: 36,),
  505. Text(_function.length>4&&index==3?'更多':'${_function[index]['name']}',style: TextStyle(color: Color(0xFF7F3344),fontSize: 11,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  506. ],
  507. ),
  508. ),
  509. );
  510. }
  511. ),
  512. ),
  513. ),
  514. Container(
  515. width: MediaQuery.of(context).size.width-10,
  516. height: 70+90.5*2,
  517. decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.all(Radius.circular(6))),
  518. margin: EdgeInsets.only(top: 5),
  519. padding: EdgeInsets.only(left: 10,right: 10,top: 10,bottom: 5),
  520. child: Column(
  521. crossAxisAlignment: CrossAxisAlignment.start,
  522. children: [
  523. Container(
  524. height: 25,
  525. child: Row(
  526. children: [
  527. Image(image:AssetImage('lib/images/zhaunjia.png'),width: 20,height: 20,),
  528. GestureDetector(
  529. onTap: (){
  530. _getDoctorData(chapter+1);
  531. },
  532. child: Container(
  533. margin: EdgeInsets.only(left: 5,right: 5),
  534. child: Text(' 问专家',style: TextStyle(color: Color(0xFF7F3344),fontSize: 13,decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  535. ),
  536. ),
  537. GestureDetector(
  538. onTap: (){
  539. _getPolicyData();
  540. },
  541. child: Text(' 问政策',style: TextStyle(color: Color(0xFF7F3344),fontSize: 13,decoration: TextDecoration.none,fontWeight: FontWeight.w600),)
  542. ),
  543. Container(width: MediaQuery.of(context).size.width-198,),
  544. CupertinoButton(
  545. padding: EdgeInsets.all(0),
  546. child: Text('大厅',style: TextStyle(color: Color(0xFF7F3344),fontSize: 13,decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  547. onPressed: (){
  548. Navigator.of(context,rootNavigator: true).push(
  549. CupertinoPageRoute(
  550. builder: (context){
  551. return YSQuestion();
  552. }
  553. )
  554. );
  555. },
  556. )
  557. ],
  558. ),
  559. ),
  560. Container(height: 2,width: 30,color: Color(0xFF7F3344),margin: EdgeInsets.only(left: pageIndex==0?35:82,bottom: 5),),
  561. Container(
  562. height: 90.0*2,
  563. child: PageView(
  564. controller: _page,
  565. onPageChanged: (index){
  566. index==0?_getDoctorData(chapter+1):_getPolicyData();
  567. },
  568. children: [
  569. Container(
  570. height: 90.0*2,
  571. child: ListView.separated(
  572. itemBuilder: (context,index){
  573. Map item = _doctors[index];
  574. return YSDoctorListView(doctorItem: item,);
  575. },
  576. separatorBuilder: (context,index){
  577. return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFE6E1E1),);
  578. },
  579. itemCount: _doctors.length>2?2:_doctors.length,
  580. physics: NeverScrollableScrollPhysics(),
  581. padding: EdgeInsets.all(0),
  582. ),
  583. ),
  584. Container(
  585. height: 90.0*2,
  586. child: ListView.separated(
  587. itemBuilder: (context,index){
  588. return GestureDetector(
  589. behavior: HitTestBehavior.opaque,
  590. onTap: (){
  591. Navigator.of(context,rootNavigator: true).push(
  592. CupertinoPageRoute(
  593. builder: (context){
  594. return YSAskQuestion(info: _doctors[index],isPolicy: true,);
  595. }
  596. )
  597. );
  598. },
  599. child: Container(
  600. height: 90,
  601. child: Row(
  602. children: [
  603. Container(
  604. height: 70,
  605. width: 70,
  606. decoration: BoxDecoration(
  607. borderRadius: BorderRadius.all(Radius.circular(35)),
  608. color: Color(0xFFD1D1D1),
  609. image: DecorationImage(
  610. fit: BoxFit.cover,
  611. image: NetworkImage('${_doctors[index]['avatar']}'),
  612. )
  613. ),
  614. ),
  615. Container(
  616. margin: EdgeInsets.only(left: 10),
  617. height: 60,
  618. width: MediaQuery.of(context).size.width-140,
  619. child: Column(
  620. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  621. crossAxisAlignment: CrossAxisAlignment.start,
  622. children: [
  623. Text('${_doctors[index]['name']}',style: TextStyle(color: Color(0xFF0F0F0F),fontSize: 14,decoration: TextDecoration.none,fontWeight: FontWeight.w600),
  624. maxLines: 1,overflow: TextOverflow.ellipsis,textAlign: TextAlign.left,),
  625. Text('${_doctors[index]['introduction']}',style: TextStyle(color: Color(0xFF0F0F0F),fontSize: 11,
  626. decoration: TextDecoration.none,fontWeight: FontWeight.normal),maxLines: 2,overflow: TextOverflow.ellipsis,),
  627. ],
  628. ),
  629. )
  630. ],
  631. ),
  632. ),
  633. );
  634. },
  635. separatorBuilder: (context,index){
  636. return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFE6E1E1),);
  637. },
  638. itemCount: _doctors.length>2?2:_doctors.length,
  639. physics: NeverScrollableScrollPhysics(),
  640. padding: EdgeInsets.all(0),
  641. ),
  642. )
  643. ],
  644. ),
  645. ),
  646. Container(
  647. height: 20,
  648. width: MediaQuery.of(context).size.width-30,
  649. child: CupertinoButton(
  650. padding: EdgeInsets.all(0),
  651. child: Text('更多',style: TextStyle(color: Color(0xFF7F3344),fontSize: 13,decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  652. onPressed: (){
  653. Navigator.of(context,rootNavigator: true).push(
  654. CupertinoPageRoute(
  655. builder: (context){
  656. return YSDoctor(isPolicy: pageIndex==0?false:true,);
  657. }
  658. )
  659. );
  660. },
  661. ),
  662. alignment: Alignment.center,
  663. )
  664. ],
  665. ),
  666. ),
  667. chapter>1?Container(
  668. width: MediaQuery.of(context).size.width-10,
  669. height: 100,
  670. decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.all(Radius.circular(6))),
  671. margin: EdgeInsets.only(top: 5),
  672. child: Container(
  673. height: 82,
  674. child: ListView.builder(
  675. scrollDirection: Axis.horizontal,
  676. itemCount: _function.length>4?4:_function.length,
  677. itemBuilder: (context,index){
  678. return GestureDetector(
  679. onTap: (){
  680. Navigator.of(context,rootNavigator: true).push(
  681. CupertinoPageRoute(
  682. builder: (context){
  683. if(_function.length>4&&index==3){
  684. return YSMore();
  685. }else if(_function[index]['value']=='PregnancyDiary'){
  686. return YSDiary();
  687. }else if(_function[index]['value']=='PregnancyBody'){
  688. return YSWomanBody();
  689. }else if(_function[index]['value']=='MotherhoodDiary'){
  690. return YSDiary();
  691. }else if(_function[index]['value']=='ChildBody'){
  692. return YSChildBody();
  693. }else if(_function[index]['value']=='ChildDiary'){
  694. return YSDiary();
  695. }else if('${_function[index]['value']}'.contains('http')==true){
  696. return YSUrlPage(url: _function[index]['value'],title: _function[index]['name']??'',);
  697. }else{
  698. return YSMore();
  699. }
  700. }
  701. )
  702. );
  703. },
  704. child: Container(
  705. height: 82,
  706. padding: EdgeInsets.only(top: 10,bottom: 10),
  707. width: (MediaQuery.of(context).size.width-10)/4,
  708. child: Column(
  709. mainAxisAlignment: MainAxisAlignment.spaceAround,
  710. children: [
  711. Image(image:_function.length>4&&index==3?AssetImage('lib/images/more.png'):NetworkImage('${_function[index]['img']}'),height: 36,width: 36,),
  712. Text(_function.length>4&&index==3?'更多':'${_function[index]['name']}',style: TextStyle(color: Color(0xFF7F3344),fontSize: 11,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  713. ],
  714. ),
  715. ),
  716. );
  717. }
  718. ),
  719. ),
  720. ):Container(),
  721. Container(
  722. width: MediaQuery.of(context).size.width-10,
  723. decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.all(Radius.circular(6))),
  724. margin: EdgeInsets.only(top: 5,bottom: 60),
  725. padding: EdgeInsets.all(10),
  726. child: Column(
  727. children: [
  728. Container(
  729. margin:EdgeInsets.only(bottom: 5),
  730. height: 20,
  731. child: Row(
  732. children: [
  733. Image(image:AssetImage('lib/images/babyCar.png'),width: 20,height: 20,),
  734. Text(' ${chapter==0?'备孕':chapter==1?'孕产':'育儿'}百科',style: TextStyle(color: Color(0xFF7F3344),fontSize: 13,decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  735. Container(width: MediaQuery.of(context).size.width-154,),
  736. CupertinoButton(
  737. padding: EdgeInsets.all(0),
  738. child: Text('更多',style: TextStyle(color: Color(0xFF7F3344),fontSize: 13,decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  739. onPressed: (){
  740. Navigator.of(context,rootNavigator: true).push(
  741. CupertinoPageRoute(
  742. builder: (context){
  743. return YSInformation();
  744. }
  745. )
  746. );
  747. },
  748. )
  749. ],
  750. ),
  751. ),
  752. Container(
  753. child: ListView.separated(
  754. shrinkWrap: true,
  755. itemBuilder: (context,index){
  756. Map item = _wiki[index];
  757. return YSWikiListView(
  758. wikiItem: item,
  759. callback: () async{
  760. SharedPreferences _prefer = await SharedPreferences.getInstance();
  761. _getChapterData(chapter+1, _prefer.getInt('childId')??0);
  762. },
  763. );
  764. },
  765. separatorBuilder: (context,index){
  766. return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFE6E1E1),);
  767. },
  768. itemCount: _wiki.length>5?5:_wiki.length,
  769. physics: NeverScrollableScrollPhysics(),
  770. padding: EdgeInsets.all(0),
  771. ),
  772. ),
  773. ],
  774. ),
  775. ),
  776. ],
  777. ),
  778. )
  779. ],
  780. ),
  781. ),
  782. ),
  783. ),
  784. ),
  785. );
  786. }
  787. Future<void> _refresh() async{
  788. SharedPreferences _prefer = await SharedPreferences.getInstance();
  789. _getChapterData(chapter+1, _prefer.getInt('childId')??0);
  790. }
  791. // _postChapterChooseData(chapter,{childId}) async{
  792. // LogUtil.d(chapter);
  793. // Map request = {};
  794. // request['period'] = chapter;
  795. // if(childId!=0){
  796. // request['child_id'] = childId;
  797. // }
  798. // Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'userPeriodState/period', request);
  799. // if(dict!=null){}
  800. // }
  801. _getChapterData(int chap,int childId) async{
  802. _getFunctionData(chap,childId);
  803. _getDoctorData(chap);
  804. _getWikiData(chap);
  805. Map param = Map();
  806. param['category_id'] = chap;
  807. if(childId!=0){
  808. param['child_id'] = childId;
  809. }
  810. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'chapter/info', param);
  811. if(dict!=null){
  812. if(chap!=1){
  813. if(chap==2){
  814. _isScroll = true;
  815. int week = dict['data']['pregnancy_week'];
  816. // if(week>0){
  817. // week = week-1;
  818. // }
  819. int day = dict['data']['pregnancy_day'];
  820. if(day>0){
  821. // day = day-1;
  822. }
  823. _getMessageData(chap, (week*7+day),true);
  824. }else{
  825. _getMessageData(chap, dict['data']['diff_in_day'],true);
  826. }
  827. }
  828. setState(() {
  829. chapter = chap-1;
  830. User().chapter = chapter;
  831. _info = dict['data'];
  832. if(chapter==2){
  833. if(dict['data']['gender']==1){
  834. isBoy = true;
  835. }else{
  836. isBoy = false;
  837. }
  838. }
  839. });
  840. }
  841. }
  842. _getMessageData(int chap,int number,bool isGet) async{
  843. number = number.abs();
  844. Map param = Map();
  845. LogUtil.d('chap=========$chap');
  846. param['category_id'] = chap;
  847. int day = number>280?280:number;
  848. if(chap==3){
  849. day = number>360?360:number;
  850. }
  851. param['day'] = day;
  852. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'chapter/tips', param);
  853. if(dict!=null){
  854. setState(() {
  855. if(chap==2){
  856. if(isGet==true){
  857. _scroll.jumpTo((day-1)*60.0);
  858. selectedIndex = day-1;
  859. }else{
  860. selectedIndex = day-1;
  861. }
  862. }else{
  863. selectedIndex = number;
  864. }
  865. Future.delayed(Duration(seconds: 1)).then((value) {
  866. _isScroll=false;
  867. });
  868. message = dict['data']['value'];
  869. });
  870. }
  871. }
  872. _getFunctionData(int chap,int childId) async{
  873. Map param = Map();
  874. param['category_id'] = chap;
  875. param['type'] = 'ios';
  876. if(childId!=0)param['child_id'] = childId;
  877. _function = await ysRequestHttpNoLoading(context, requestType.post, 'tool/list', param)??[];
  878. if(_function.length>0){
  879. setState(() {});
  880. }
  881. }
  882. _getDoctorData(int chap) async{
  883. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'doctor/list', {'category_id':chap});
  884. if(dict!=null){
  885. setState(() {
  886. pageIndex = 0;
  887. _page.jumpToPage(0);
  888. _doctors = dict['data']??[];
  889. });
  890. }
  891. }
  892. _getPolicyData() async{
  893. var dict = await ysRequestHttpNoLoading(context, requestType.get, 'policy/doctor', {});
  894. if(dict!=null){
  895. setState(() {
  896. pageIndex = 1;
  897. _page.jumpToPage(1);
  898. _doctors = dict;
  899. });
  900. }
  901. }
  902. _getWikiData(int chap) async{
  903. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'wike/list', {'category_id':chap});
  904. if(dict!=null){
  905. setState(() {
  906. _wiki = dict['data']??[];
  907. });
  908. }
  909. }
  910. _postPeriodData(int type) async{
  911. String date = DateTime.now().year.toString()+'-'+DateTime.now().month.toString()+'-'+DateTime.now().day.toString();
  912. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'motherhood/periodDate/add', {'type':type.toString(),'date':date});
  913. if(dict!=null){
  914. setState(() {
  915. if(type==1){
  916. _isPeriod = true;
  917. }else{
  918. _isRoom = true;
  919. }
  920. });
  921. }
  922. }
  923. _deletePeriodData(int type) async{
  924. String date = DateTime.now().year.toString()+'-'+DateTime.now().month.toString()+'-'+DateTime.now().day.toString();
  925. Map dict = await ysRequestHttpNoLoading(context, requestType.delete, 'motherhood/periodDate/delete', {'type':type.toString(),'date':date});
  926. if(dict!=null){
  927. setState(() {
  928. if(type==1){
  929. _isPeriod = false;
  930. }else{
  931. _isRoom = false;
  932. }
  933. });
  934. }
  935. }
  936. _getUserData() async{
  937. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'user/info', {});
  938. if(dict!=null){
  939. User().userId = '${dict['id']}';
  940. User().avatar = '${dict['avatar']}';
  941. User().name = dict['simple_name']??dict['username']??'';
  942. User().idCard = dict['id_card']??'';
  943. }
  944. }
  945. }