YSSightseeingPlane.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_easyrefresh/easy_refresh.dart';
  4. import 'package:shared_preferences/shared_preferences.dart';
  5. import 'package:ysairplane2/code/YSMarryPlane.dart';
  6. import 'package:ysairplane2/code/YSSearchResult.dart';
  7. import 'package:ysairplane2/tools/YSNetWorking.dart';
  8. import 'package:ysairplane2/tools/YSTools.dart';
  9. enum planeType{
  10. sightseeing,
  11. sport,
  12. marry,
  13. }
  14. class YSSightseeingPlane extends StatefulWidget {
  15. final planeType type;
  16. const YSSightseeingPlane({Key key, this.type}) : super(key: key);
  17. @override
  18. _YSSightseeingPlaneState createState() => _YSSightseeingPlaneState();
  19. }
  20. class _YSSightseeingPlaneState extends State<YSSightseeingPlane> {
  21. Map _msgDict;
  22. List _titles = ['综合','距离','价格','评分'];
  23. int _titleIndex = 0;
  24. int _page = 1;
  25. List _dataArray = [];
  26. int _type;
  27. String _cityStr = '';
  28. @override
  29. void initState() {
  30. Future.delayed(Duration(seconds: 0)).then((value){
  31. _type = widget.type==planeType.marry?4:widget.type==planeType.sport?5:9;
  32. _getBackImageData();
  33. _refreshData();
  34. });
  35. super.initState();
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. return Scaffold(
  40. backgroundColor: Color(0xFFF1F2F3),
  41. body: SingleChildScrollView(
  42. padding: EdgeInsets.all(0),
  43. child: Stack(
  44. children: [
  45. Container(
  46. height: MediaQuery.of(context).padding.top+hsp(370),
  47. width: MediaQuery.of(context).size.width,
  48. child: _msgDict==null?Image(
  49. image: AssetImage('lib/images/home3.png'),
  50. fit: BoxFit.fill,
  51. ):ysImageLoad(
  52. imageUrl: '${_msgDict['background']}',
  53. fit: BoxFit.fill,
  54. height: MediaQuery.of(context).padding.top+hsp(370),
  55. width: MediaQuery.of(context).size.width,
  56. ),
  57. ),
  58. GestureDetector(
  59. onTap: (){
  60. Navigator.pop(context);
  61. },
  62. child: Container(
  63. margin: EdgeInsets.only(left: hsp(30),right: wsp(30),top: MediaQuery.of(context).padding.top+hsp(50)),
  64. child: Icon(Icons.arrow_back_ios,color: Colors.white,size: hsp(50),),
  65. ),
  66. ),
  67. GestureDetector(
  68. onTap: (){
  69. Navigator.of(context).push(
  70. CupertinoPageRoute(builder: (context){
  71. return YSSearchResult(type: _type,);
  72. })
  73. );
  74. },
  75. child : Container(
  76. margin: EdgeInsets.only(left: hsp(110),top: MediaQuery.of(context).padding.top+hsp(45)),
  77. width: MediaQuery.of(context).size.width-hsp(140),
  78. height: hsp(60),
  79. decoration: BoxDecoration(
  80. color: Colors.black.withOpacity(0.35),
  81. borderRadius: BorderRadius.all(Radius.circular(50))
  82. ),
  83. padding: EdgeInsets.only(left: wsp(30),right: wsp(30)),
  84. child: Row(
  85. children: [
  86. Row(
  87. children: [
  88. Text(_cityStr,style: TextStyle(fontSize: zsp(26),color: Colors.white),),
  89. Icon(Icons.keyboard_arrow_down,color: Colors.white.withOpacity(0.5),size: hsp(40),)
  90. ],
  91. ),
  92. Container(
  93. height: hsp(30),
  94. width: 0.5,
  95. margin: EdgeInsets.only(left: wsp(10),right: wsp(10)),
  96. color: Colors.white.withOpacity(0.2),
  97. ),
  98. Row(
  99. children: [
  100. Icon(Icons.search,color: Colors.white.withOpacity(0.5),size: hsp(50),),
  101. Text(' 搜索',style: TextStyle(fontSize: zsp(26),color: Colors.white.withOpacity(0.5)),),
  102. ],
  103. )
  104. ],
  105. ),
  106. ),
  107. ),
  108. if(_msgDict!=null)Container(
  109. margin: EdgeInsets.only(left: wsp(50),top: MediaQuery.of(context).padding.top+hsp(250)),
  110. child: RichText(
  111. text: TextSpan(
  112. text: '${_msgDict['name']} ',
  113. style: TextStyle(fontSize: zsp(50),color: Colors.white,fontWeight: FontWeight.bold),
  114. children: [
  115. TextSpan(
  116. text: '${_msgDict['subtitle']}',
  117. style: TextStyle(fontWeight: FontWeight.normal,fontSize: zsp(28),color: Colors.white.withOpacity(0.5))
  118. )
  119. ]
  120. ),
  121. ),
  122. ),
  123. Container(
  124. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(350)),
  125. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-hsp(350),
  126. width: MediaQuery.of(context).size.width,
  127. decoration: BoxDecoration(
  128. color: Color(0xFFF1F2F3),
  129. borderRadius: BorderRadius.only(topRight: Radius.circular(10),topLeft: Radius.circular(10))
  130. ),
  131. child: Column(
  132. children: [
  133. Container(
  134. width: MediaQuery.of(context).size.width,
  135. height: hsp(80),
  136. child: ListView.builder(
  137. itemBuilder: (context,index){
  138. return GestureDetector(
  139. onTap: (){
  140. _titleIndex = index;
  141. _refreshData();
  142. },
  143. child: Container(
  144. height: hsp(80),
  145. width: MediaQuery.of(context).size.width/4,
  146. alignment: Alignment.center,
  147. child: Text('${_titles[index]}',style: TextStyle(fontSize: zsp(26),color: _titleIndex==index?Color(0xFF007AFF):Color(0xFF222222),fontWeight: _titleIndex==index?FontWeight.bold:FontWeight.normal),),
  148. ),
  149. );
  150. },
  151. itemCount: _titles.length,
  152. padding: EdgeInsets.all(0),
  153. scrollDirection: Axis.horizontal,
  154. ),
  155. ),
  156. Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEEEEEE),),
  157. Container(
  158. width: MediaQuery.of(context).size.width,
  159. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-hsp(430)-0.5,
  160. child: EasyRefresh(
  161. onRefresh: _refreshData,
  162. onLoad: _loadMoreData,
  163. header: TaurusHeader(
  164. ),
  165. footer: TaurusFooter(
  166. ),
  167. child: ListView.separated(
  168. itemBuilder: (context,index){
  169. return GestureDetector(
  170. behavior: HitTestBehavior.opaque,
  171. onTap: (){
  172. Navigator.of(context).push(
  173. CupertinoPageRoute(
  174. builder: (context){
  175. return YSMarryPlane(marryId: _dataArray[index]['id'],type: _type);
  176. }
  177. )
  178. );
  179. },
  180. child: Container(
  181. padding: EdgeInsets.all(hsp(30)),
  182. child: Row(
  183. children: [
  184. Container(
  185. height: hsp(200),
  186. width: hsp(250),
  187. child: ysImageLoad(
  188. imageUrl: '${_dataArray[index]['cover']}',
  189. fit: BoxFit.fill,
  190. height: hsp(200),
  191. width: hsp(250),
  192. ),
  193. margin: EdgeInsets.only(right: hsp(30)),
  194. ),
  195. Container(
  196. width: MediaQuery.of(context).size.width-hsp(340),
  197. height: hsp(200),
  198. child: Column(
  199. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  200. crossAxisAlignment: CrossAxisAlignment.start,
  201. children: [
  202. Text('${_dataArray[index]['title']}',style: TextStyle(fontSize: zsp(30),color: Color(0xFF343434)),maxLines: 2,),
  203. Text('${_dataArray[index]['dtFlightInformation']['partnerName']}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF9A9A9A)),),
  204. Row(
  205. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  206. children: [
  207. Text('${_dataArray[index]['dtFlightInformation']['model']}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF9A9A9A)),),
  208. RichText(
  209. text: TextSpan(
  210. text: '¥',
  211. style: TextStyle(fontSize: zsp(24),color: Color(0xFFEB423B)),
  212. children: [
  213. TextSpan(
  214. text: '${_dataArray[index]['discountPrice']}',
  215. style: TextStyle(fontSize: zsp(42),fontWeight: FontWeight.bold),
  216. ),
  217. TextSpan(
  218. text: '元起',
  219. style: TextStyle(fontSize: zsp(20)),
  220. )
  221. ]
  222. ),
  223. )
  224. ],
  225. )
  226. ],
  227. ),
  228. )
  229. ],
  230. ),
  231. ),
  232. );
  233. },
  234. separatorBuilder: (context,index){
  235. return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEEEEEE),);
  236. },
  237. itemCount: _dataArray.length,
  238. padding: EdgeInsets.all(0),
  239. ),
  240. ),
  241. ),
  242. ],
  243. ),
  244. ),
  245. ],
  246. ),
  247. ),
  248. );
  249. }
  250. _getBackImageData() async{
  251. SharedPreferences preferences = await SharedPreferences.getInstance();
  252. _cityStr = preferences.getString('location');
  253. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/wallconfigure/get',parameter: {'type':_type},isLoading: false,isToken: false);
  254. if(dict!=null){
  255. setState(() {
  256. _msgDict = dict['data'];
  257. });
  258. }
  259. }
  260. Future<void> _refreshData() async{
  261. _page = 1;
  262. Map request = {};
  263. request['category'] = _type;
  264. request['pageNo'] = _page;
  265. request['pageSize'] = 10;
  266. if(_titles[_titleIndex]=='距离'){
  267. request['type'] = 1;
  268. request['location'] = '108.985463,34.30501';
  269. }else if(_titles[_titleIndex]=='价格'){
  270. request['type'] = 2;
  271. }else if(_titles[_titleIndex]=='评分'){
  272. request['type'] = 3;
  273. }else{
  274. request['type'] = 4;
  275. }
  276. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/AirTour/list',parameter: request,isLoading: false,isToken: false);
  277. if(dict!=null){
  278. setState(() {
  279. _dataArray = dict['data']['resultList'];
  280. });
  281. }
  282. }
  283. Future<void> _loadMoreData() async{
  284. _page++;
  285. Map request = {};
  286. request['category'] = _type;
  287. request['pageNo'] = _page;
  288. request['pageSize'] = 10;
  289. if(_titles[_titleIndex]=='距离'){
  290. request['type'] = 1;
  291. request['location'] = '108.985463,34.30501';
  292. }else if(_titles[_titleIndex]=='价格'){
  293. request['type'] = 2;
  294. }else if(_titles[_titleIndex]=='评分'){
  295. request['type'] = 3;
  296. }else{
  297. request['type'] = 4;
  298. }
  299. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/AirTour/list',parameter: request,isLoading: false,isToken: false);
  300. if(dict!=null){
  301. setState(() {
  302. _dataArray.addAll(dict['data']['resultList']);
  303. });
  304. }
  305. }
  306. }