import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:ysairplane2/code/YSMarryPlane.dart'; import 'package:ysairplane2/code/YSSearchResult.dart'; import 'package:ysairplane2/tools/YSNetWorking.dart'; import 'package:ysairplane2/tools/YSTools.dart'; enum planeType{ sightseeing, sport, marry, } class YSSightseeingPlane extends StatefulWidget { final planeType type; const YSSightseeingPlane({Key key, this.type}) : super(key: key); @override _YSSightseeingPlaneState createState() => _YSSightseeingPlaneState(); } class _YSSightseeingPlaneState extends State { Map _msgDict; List _titles = ['综合','距离','价格','评分']; int _titleIndex = 0; int _page = 1; List _dataArray = []; int _type; String _cityStr = ''; @override void initState() { Future.delayed(Duration(seconds: 0)).then((value){ _type = widget.type==planeType.marry?4:widget.type==planeType.sport?5:9; _getBackImageData(); _refreshData(); }); super.initState(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Color(0xFFF1F2F3), body: SingleChildScrollView( padding: EdgeInsets.all(0), child: Stack( children: [ Container( height: MediaQuery.of(context).padding.top+hsp(370), width: MediaQuery.of(context).size.width, child: _msgDict==null?Image( image: AssetImage('lib/images/home3.png'), fit: BoxFit.fill, ):ysImageLoad( imageUrl: '${_msgDict['background']}', fit: BoxFit.fill, height: MediaQuery.of(context).padding.top+hsp(370), width: MediaQuery.of(context).size.width, ), ), GestureDetector( onTap: (){ Navigator.pop(context); }, child: Container( margin: EdgeInsets.only(left: hsp(30),right: wsp(30),top: MediaQuery.of(context).padding.top+hsp(50)), child: Icon(Icons.arrow_back_ios,color: Colors.white,size: hsp(50),), ), ), GestureDetector( onTap: (){ Navigator.of(context).push( CupertinoPageRoute(builder: (context){ return YSSearchResult(type: _type,); }) ); }, child : Container( margin: EdgeInsets.only(left: hsp(110),top: MediaQuery.of(context).padding.top+hsp(45)), width: MediaQuery.of(context).size.width-hsp(140), height: hsp(60), decoration: BoxDecoration( color: Colors.black.withOpacity(0.35), borderRadius: BorderRadius.all(Radius.circular(50)) ), padding: EdgeInsets.only(left: wsp(30),right: wsp(30)), child: Row( children: [ Row( children: [ Text(_cityStr,style: TextStyle(fontSize: zsp(26),color: Colors.white),), Icon(Icons.keyboard_arrow_down,color: Colors.white.withOpacity(0.5),size: hsp(40),) ], ), Container( height: hsp(30), width: 0.5, margin: EdgeInsets.only(left: wsp(10),right: wsp(10)), color: Colors.white.withOpacity(0.2), ), Row( children: [ Icon(Icons.search,color: Colors.white.withOpacity(0.5),size: hsp(50),), Text(' 搜索',style: TextStyle(fontSize: zsp(26),color: Colors.white.withOpacity(0.5)),), ], ) ], ), ), ), if(_msgDict!=null)Container( margin: EdgeInsets.only(left: wsp(50),top: MediaQuery.of(context).padding.top+hsp(250)), child: RichText( text: TextSpan( text: '${_msgDict['name']} ', style: TextStyle(fontSize: zsp(50),color: Colors.white,fontWeight: FontWeight.bold), children: [ TextSpan( text: '${_msgDict['subtitle']}', style: TextStyle(fontWeight: FontWeight.normal,fontSize: zsp(28),color: Colors.white.withOpacity(0.5)) ) ] ), ), ), Container( margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(350)), height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-hsp(350), width: MediaQuery.of(context).size.width, decoration: BoxDecoration( color: Color(0xFFF1F2F3), borderRadius: BorderRadius.only(topRight: Radius.circular(10),topLeft: Radius.circular(10)) ), child: Column( children: [ Container( width: MediaQuery.of(context).size.width, height: hsp(80), child: ListView.builder( itemBuilder: (context,index){ return GestureDetector( onTap: (){ _titleIndex = index; _refreshData(); }, child: Container( height: hsp(80), width: MediaQuery.of(context).size.width/4, alignment: Alignment.center, child: Text('${_titles[index]}',style: TextStyle(fontSize: zsp(26),color: _titleIndex==index?Color(0xFF007AFF):Color(0xFF222222),fontWeight: _titleIndex==index?FontWeight.bold:FontWeight.normal),), ), ); }, itemCount: _titles.length, padding: EdgeInsets.all(0), scrollDirection: Axis.horizontal, ), ), Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEEEEEE),), Container( width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-hsp(430)-0.5, child: EasyRefresh( onRefresh: _refreshData, onLoad: _loadMoreData, header: TaurusHeader( ), footer: TaurusFooter( ), child: ListView.separated( itemBuilder: (context,index){ return GestureDetector( behavior: HitTestBehavior.opaque, onTap: (){ Navigator.of(context).push( CupertinoPageRoute( builder: (context){ return YSMarryPlane(marryId: _dataArray[index]['id'],type: _type); } ) ); }, child: Container( padding: EdgeInsets.all(hsp(30)), child: Row( children: [ Container( height: hsp(200), width: hsp(250), child: ysImageLoad( imageUrl: '${_dataArray[index]['cover']}', fit: BoxFit.fill, height: hsp(200), width: hsp(250), ), margin: EdgeInsets.only(right: hsp(30)), ), Container( width: MediaQuery.of(context).size.width-hsp(340), height: hsp(200), child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('${_dataArray[index]['title']}',style: TextStyle(fontSize: zsp(30),color: Color(0xFF343434)),maxLines: 2,overflow: TextOverflow.ellipsis,), Text('${_dataArray[index]['dtFlightInformation']['partnerName']}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF9A9A9A)),), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('${_dataArray[index]['dtFlightInformation']['model']}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF9A9A9A)),), RichText( text: TextSpan( text: '¥', style: TextStyle(fontSize: zsp(24),color: Color(0xFFEB423B)), children: [ TextSpan( text: '${_dataArray[index]['discountPrice']}', style: TextStyle(fontSize: zsp(42),fontWeight: FontWeight.bold), ), TextSpan( text: '元起', style: TextStyle(fontSize: zsp(20)), ) ] ), ) ], ) ], ), ) ], ), ), ); }, separatorBuilder: (context,index){ return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEEEEEE),); }, itemCount: _dataArray.length, padding: EdgeInsets.all(0), ), ), ), ], ), ), ], ), ), ); } _getBackImageData() async{ SharedPreferences preferences = await SharedPreferences.getInstance(); _cityStr = preferences.getString('location'); Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/wallconfigure/get',parameter: {'type':_type},isLoading: false,isToken: false); if(dict!=null){ setState(() { _msgDict = dict['data']; }); } } Future _refreshData() async{ _page = 1; Map request = {}; request['category'] = _type; request['pageNo'] = _page; request['pageSize'] = 10; if(_titles[_titleIndex]=='距离'){ request['type'] = 1; request['location'] = '108.985463,34.30501'; }else if(_titles[_titleIndex]=='价格'){ request['type'] = 2; }else if(_titles[_titleIndex]=='评分'){ request['type'] = 3; }else{ request['type'] = 4; } Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/AirTour/list',parameter: request,isLoading: false,isToken: false); if(dict!=null){ setState(() { _dataArray = dict['data']['resultList']; }); } } Future _loadMoreData() async{ _page++; Map request = {}; request['category'] = _type; request['pageNo'] = _page; request['pageSize'] = 10; if(_titles[_titleIndex]=='距离'){ request['type'] = 1; request['location'] = '108.985463,34.30501'; }else if(_titles[_titleIndex]=='价格'){ request['type'] = 2; }else if(_titles[_titleIndex]=='评分'){ request['type'] = 3; }else{ request['type'] = 4; } Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/AirTour/list',parameter: request,isLoading: false,isToken: false); if(dict!=null){ setState(() { _dataArray.addAll(dict['data']['resultList']); }); } } }