import 'dart:convert'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:ysairplane/code/YSCity.dart'; import 'package:ysairplane/code/YSDoctorPlane.dart'; import 'package:ysairplane/code/YSHelpPlane.dart'; import 'package:ysairplane/code/YSHomeMsg.dart'; import 'package:ysairplane/code/YSSearch.dart'; import 'package:ysairplane/code/YSShortGoods.dart'; import 'package:ysairplane/code/YSShortPlane.dart'; import 'package:ysairplane/code/YSTravelling.dart'; import 'package:ysairplane/tools/YSNetWorking.dart'; import 'package:flutter_swiper/flutter_swiper.dart'; import 'package:ysairplane/code/YSNews.dart'; import 'package:ysairplane/tools/YSTools.dart'; import 'YSContractPlane.dart'; import 'YSSightseeingPlane.dart'; class YSHome extends StatefulWidget { @override _YSHomeState createState() => _YSHomeState(); } class _YSHomeState extends State with AutomaticKeepAliveClientMixin{ @override bool get wantKeepAlive => true; List _banners = List(); List _products = List(); Map _advertising; String _city = ''; List _dataArray = []; @override void initState() { Future.delayed(Duration(seconds: 0)).then((value){ _getFeatureDisplayShowData(); }); super.initState(); } @override Widget build(BuildContext context) { super.build(context); return Scaffold( backgroundColor: Colors.white, appBar: CupertinoNavigationBar( leading: GestureDetector( onTap: (){ Navigator.of(context,rootNavigator: true).push( CupertinoPageRoute( builder: (context){ return YSCity(); } ) ).then((value){ if(value!=null){ _city = value['display']; _getFeatureDisplayListData(_city); // _getFeatureDisplayListData(); } }); }, child: Row( mainAxisSize: MainAxisSize.min, children: [ Container( width: hsp(35*(_city.length>5?5:_city.length)), child: Text(_city,style: TextStyle(fontSize: zsp(28),color: Color(0xFF8E8E93)),overflow: TextOverflow.ellipsis,), ), Icon(Icons.keyboard_arrow_down,size: zsp(30),color: Color(0xFF8E8E93),) ], ), ), middle: GestureDetector( onTap: (){ Navigator.of(context,rootNavigator: true).push( CupertinoPageRoute( builder: (context){ return YSSearch(); } ) ); }, child: Container( height: hsp(66), padding: EdgeInsets.only(left: wsp(30),right: wsp(30)), decoration: BoxDecoration( color: Color(0xFFF0F0F1), borderRadius: BorderRadius.all(Radius.circular(5)) ), child: Row( children: [ Icon(Icons.search,size: hsp(40),color: Color(0xFF8E8E93),), Text(' 目的地·酒店·关键词',style: TextStyle(fontSize: zsp(28),color: Color(0xFF8E8E93),fontWeight: FontWeight.normal),) ], ), ), ), trailing: GestureDetector( onTap: (){ Navigator.of(context,rootNavigator: true).push( CupertinoPageRoute( builder: (context){ return YSHomeMsg(); } ) ); }, child: Container( height: hsp(45), width: wsp(45), child: Image.asset('lib/images/homeMsg.png'), ), ), border: Border.all(width: 0.5,color: Colors.white), ), body: Container( height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-94, child: SingleChildScrollView( padding: EdgeInsets.all(0), child: Column( children: [ Container( height: hsp(292), margin: EdgeInsets.all(hsp(24)), child: _banners.length>0?Swiper( itemBuilder: (BuildContext context, int index) { return CachedNetworkImage( imageUrl: '${_banners[index]['url']}', fit: BoxFit.fill, ); }, itemCount: _banners.length, scrollDirection: Axis.horizontal, loop: true, duration: 300, autoplay: true, onTap: (index) { debugPrint("点击了第:$index个"); }, pagination: SwiperPagination( alignment: Alignment.bottomCenter, builder: DotSwiperPaginationBuilder( color: Colors.white, activeColor: Colors.white, size: 5.0, activeSize: 10.0 ), ), autoplayDisableOnInteraction : true, ):Container(), ), Container( margin: EdgeInsets.only(left: hsp(24),right: hsp(24),top: hsp(15),bottom: hsp(34)), height: hsp(350), child: GridView.builder( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 5, crossAxisSpacing: wsp(51), mainAxisSpacing: hsp(36), childAspectRatio: 0.8 ), itemBuilder: (context,index){ return GestureDetector( onTap: (){ Navigator.of(context,rootNavigator: true).push( CupertinoPageRoute( builder: (context){ return _products[index]['target']==1?YSDoctorPlane():_products[index]['target']==2?YSHelpPlane():_products[index]['target']==3?YSShortGoods(): _products[index]['target']==4?YSSightseeingPlane(type: planeType.marry,):_products[index]['target']==5?YSSightseeingPlane(type: planeType.sport,):_products[index]['target']==6?YSShortPlane(): _products[index]['target']==7?YSTravelling():_products[index]['target']==8?YSContractPlane():_products[index]['target']==9?YSSightseeingPlane(type: planeType.sightseeing,):YSNews(); } ) ); }, child: Container( child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ CachedNetworkImage( width: 40, height: 40, imageUrl: '${_products[index]['url']}', fit: BoxFit.fill ), Text('${_products[index]['name']}',style: TextStyle(fontSize: zsp(23),color: Color(0xFF34373A)),) ], ), ), ); }, itemCount: _products.length, padding: EdgeInsets.all(0), physics: NeverScrollableScrollPhysics(), ), ), if(_advertising!=null)Container( margin: EdgeInsets.only(left: hsp(24),right: hsp(24),bottom: hsp(24)), height: wsp(136), decoration: BoxDecoration( image: DecorationImage( image: NetworkImage('${_advertising['url']}'), fit: BoxFit.fill ) ), ), Divider(height: 10,thickness: 10,color: Color(0xFFF5F6F8),), ListView.separated( itemBuilder: (context,index){ return _dataArray[index]['displayType']=='1'?Column( children: [ Container( height: hsp(100), padding: EdgeInsets.all(hsp(24)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Container( height: hsp(36), width: wsp(5), color: Color(0xFF3676EC), margin: EdgeInsets.only(right: wsp(20),top: hsp(8)), ), Text('${_dataArray[index]['labelName']}',style: TextStyle(fontSize: zsp(36),color: Color(0xFF181818),fontWeight: FontWeight.bold),) ], ), Row( children: [ Text('更多',style: TextStyle(fontSize: zsp(24),color: Color(0xFF999999)),), Icon(Icons.keyboard_arrow_right,size: hsp(30),color: Color(0xFF999999),) ], ) ], ), ), Divider(height: 0.5,thickness: 0.5,color: Color(0xFFF1F2F2),), Container( height: hsp(387), margin: EdgeInsets.all(hsp(24)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Stack( children: [ Container( height: hsp(387), width: (MediaQuery.of(context).size.width-wsp(24)*2-wsp(6))/2, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(5)) ), child: ClipRRect( child: CachedNetworkImage( imageUrl: '${_dataArray[index]['dtAirTours'][0]['cover']}', fit: BoxFit.fill, ), borderRadius: BorderRadius.all(Radius.circular(5)), ) ), Container( height: hsp(40), alignment: Alignment.centerLeft, child: Text('${_dataArray[index]['dtAirTours'][0]['title']}',style: TextStyle(fontSize: zsp(20),color: Colors.white),), decoration: BoxDecoration( color: Colors.black26, borderRadius: BorderRadius.only(bottomRight: Radius.circular(5),topLeft: Radius.circular(5)) ), padding: EdgeInsets.only(left: hsp(10),right: hsp(10)), ) ], ), Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Stack( children: [ Container( height: hsp(387)/2-wsp(6), width: (MediaQuery.of(context).size.width-wsp(24)*2-wsp(6))/2, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(5)) ), child: ClipRRect( child: CachedNetworkImage( imageUrl: '${_dataArray[index]['dtAirTours'][1]['cover']}', fit: BoxFit.fill, ), borderRadius: BorderRadius.all(Radius.circular(5)), ) ), Container( height: hsp(40), alignment: Alignment.centerLeft, child: Text('${_dataArray[index]['dtAirTours'][1]['title']}',style: TextStyle(fontSize: zsp(20),color: Colors.white),), decoration: BoxDecoration( color: Color(0xFFEC6163), borderRadius: BorderRadius.only(bottomRight: Radius.circular(5),topLeft: Radius.circular(5)) ), padding: EdgeInsets.only(left: hsp(10),right: hsp(10)), ) ], ), Stack( children: [ Container( height: hsp(387)/2-wsp(6), width: (MediaQuery.of(context).size.width-wsp(24)*2-wsp(6))/2, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(5)) ), child: ClipRRect( child: CachedNetworkImage( imageUrl: '${_dataArray[index]['dtAirTours'][2]['cover']}', fit: BoxFit.fill, ), borderRadius: BorderRadius.all(Radius.circular(5)), ) ), Container( height: hsp(40), alignment: Alignment.centerLeft, child: Text('${_dataArray[index]['dtAirTours'][2]['title']}',style: TextStyle(fontSize: zsp(20),color: Colors.white),), decoration: BoxDecoration( color: Color(0xFFFB882E), borderRadius: BorderRadius.only(bottomRight: Radius.circular(5),topLeft: Radius.circular(5)) ), padding: EdgeInsets.only(left: hsp(10),right: hsp(10)), ) ], ), ], ) ], ), ), ], ):_dataArray[index]['displayType']=='2'?Column( children: [ Container( height: hsp(100), color: Colors.white, padding: EdgeInsets.all(hsp(24)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Container( height: hsp(36), width: wsp(5), color: Color(0xFF3676EC), margin: EdgeInsets.only(right: wsp(20),top: hsp(8)), ), Text('${_dataArray[index]['labelName']}',style: TextStyle(fontSize: zsp(36),color: Color(0xFF181818),fontWeight: FontWeight.bold),) ], ), Row( children: [ Text('更多',style: TextStyle(fontSize: zsp(24),color: Color(0xFF999999)),), Icon(Icons.keyboard_arrow_right,size: hsp(30),color: Color(0xFF999999),) ], ) ], ), ), Divider(height: 0.5,thickness: 0.5,color: Color(0xFFF1F2F2),), Container( height: hsp(420), margin: EdgeInsets.only(top: hsp(24),bottom: hsp(24),left: wsp(40),right: wsp(24)), child: Swiper( itemBuilder: (BuildContext context, int indexSub) { return Container( width: wsp(350), margin: EdgeInsets.only(bottom: hsp(20),top: hsp(10)), decoration: BoxDecoration( color: Colors.white, boxShadow: [ BoxShadow( color: Color(0x1A000000), blurRadius: wsp(20), offset: Offset(1, 1), ) ] ), child: Column( children: [ Stack( children: [ Container( height: hsp(200), width: wsp(350), decoration: BoxDecoration( borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)), ), child: ClipRRect( child: CachedNetworkImage( imageUrl: '${_dataArray[index]['dtAirTours'][indexSub]['cover']}', fit: BoxFit.fill, ), borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)), ) ), Row( children: [ Container( height: hsp(32), alignment: Alignment.centerLeft, child: Text('西安',style: TextStyle(fontSize: zsp(20),color: Colors.white),), decoration: BoxDecoration( color: Color(0xFFE9C68E), borderRadius: BorderRadius.only(topLeft: Radius.circular(5),bottomRight: Radius.circular(5)) ), padding: EdgeInsets.only(left: hsp(10),right: hsp(10)), ) ], ) ], ), Container( decoration: BoxDecoration( borderRadius: BorderRadius.only(bottomLeft: Radius.circular(5),bottomRight: Radius.circular(5)), ), child: Column( children: [ Container( width: wsp(350), child: Text('${_dataArray[index]['dtAirTours'][indexSub]['title']}', style: TextStyle(fontSize: zsp(28),fontWeight: FontWeight.bold,color: Color(0xFF181818)),overflow: TextOverflow.ellipsis,maxLines: 2,), margin: EdgeInsets.only(top: hsp(20),bottom: hsp(15)), ), SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( children: [ Text('¥',style: TextStyle(fontSize: zsp(20),color: Color(0xFFEB423B),fontWeight: FontWeight.bold),), Text('${_dataArray[index]['dtAirTours'][indexSub]['price']}',style: TextStyle(fontSize: zsp(38),color: Color(0xFFEB423B),fontWeight: FontWeight.bold),), Text(' 元起',style: TextStyle(fontSize: zsp(20),color: Color(0xFFEB423B),fontWeight: FontWeight.bold),), Text('${_dataArray[index]['dtAirTours'][indexSub]['dtFlightInformation']['seatNum']}人体验',style: TextStyle(fontSize: zsp(16),color: Color(0xFFA2A2A2),fontWeight: FontWeight.normal),), ], ), ) ], crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, ), padding: EdgeInsets.all(hsp(20)), ) ], ), ); }, itemCount: (_dataArray[index]['dtAirTours']).length, scrollDirection: Axis.horizontal, loop: true, viewportFraction: 0.5, scale: 0.8, onTap: (index) { debugPrint("点击了第:$index个"); }, ), ), ], ):Column( children: [ Container( height: hsp(100), color: Colors.white, padding: EdgeInsets.all(hsp(24)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Container( height: hsp(36), width: wsp(5), color: Color(0xFF3676EC), margin: EdgeInsets.only(right: wsp(20),top: hsp(8)), ), Text('${_dataArray[index]['labelName']}',style: TextStyle(fontSize: zsp(36),color: Color(0xFF181818),fontWeight: FontWeight.bold),) ], ), Row( children: [ Text('更多',style: TextStyle(fontSize: zsp(24),color: Color(0xFF999999)),), Icon(Icons.keyboard_arrow_right,size: hsp(30),color: Color(0xFF999999),) ], ) ], ), ), Divider(height: 0.5,thickness: 0.5,color: Color(0xFFF1F2F2),), Container( height: hsp(470), margin: EdgeInsets.all(hsp(24)), child: ListView.separated( scrollDirection: Axis.horizontal, itemBuilder: (context,indexSub){ return Container( height: hsp(450), width: wsp(350), decoration: BoxDecoration( color: Colors.white, boxShadow: [ BoxShadow( color: Color(0x1A000000), blurRadius: wsp(20), offset: Offset(1, 1), ) ] ), child: Column( children: [ Stack( children: [ Container( height: hsp(210), width: wsp(330), decoration: BoxDecoration( borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)), ), child: ClipRRect( child: CachedNetworkImage( imageUrl: '${_dataArray[index]['dtAirTours'][indexSub]['cover']}', fit: BoxFit.fill, ), borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)), ) ), Row( children: [ if(_dataArray[index]['dtAirTours'][indexSub]['isVip']==1)Container( height: hsp(32), width: wsp(59), decoration: BoxDecoration( color: Color(0xFFE9C68E), borderRadius: BorderRadius.only(topLeft: Radius.circular(5),bottomRight: Radius.circular(5)) ), padding: EdgeInsets.only(left: wsp(10),right: wsp(10)), child: Image.asset('lib/images/vip.png'), ) ], ) ], ), Container( height: hsp(240), decoration: BoxDecoration( borderRadius: BorderRadius.only(bottomLeft: Radius.circular(5),bottomRight: Radius.circular(5)), ), child: Column( children: [ Container( width: wsp(330), child: Text('${_dataArray[index]['dtAirTours'][indexSub]['title']}',style: TextStyle(fontSize: zsp(32),fontWeight: FontWeight.bold,color: Color(0xFF181818)),overflow: TextOverflow.ellipsis,), ), Row( children: [ Container( height: hsp(30), child: Row( children: [ Image(image: AssetImage('lib/images/vip2.png'),height: hsp(15),width: wsp(16),), Text(' ${_dataArray[index]['dtAirTours'][indexSub]['dtFlightInformation']['model']}',style: TextStyle(fontSize: zsp(18),color: Color(0xFFF9DEAC)),) ], ), color: Color(0xFF000000), padding: EdgeInsets.only(left: wsp(7),right: wsp(7)), ), Container( height: hsp(30), decoration: BoxDecoration( border: Border.all(color: Color(0xFF000000),width: 0.1) ), padding: EdgeInsets.only(left: wsp(10),right: wsp(10)), child: Text('座位${_dataArray[index]['dtAirTours'][indexSub]['dtFlightInformation']['seatNum']}',style: TextStyle(fontSize: zsp(18),color: Color(0xFF565656)),), alignment: Alignment.center, ) ], ), Text('${_dataArray[index]['dtAirTours'][indexSub]['flightTime']}',style: TextStyle(fontSize: zsp(24),color: Color(0xFFA2A2A2)),), SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( children: [ Text('¥',style: TextStyle(fontSize: zsp(20),color: Color(0xFFEB423B),fontWeight: FontWeight.bold),), Text('${_dataArray[index]['dtAirTours'][indexSub]['discountPrice']}',style: TextStyle(fontSize: zsp(38),color: Color(0xFFEB423B),fontWeight: FontWeight.bold),), Text(' 元起/座',style: TextStyle(fontSize: zsp(20),color: Color(0xFFEB423B),fontWeight: FontWeight.bold),), Text(' ¥${_dataArray[index]['dtAirTours'][indexSub]['price']}元起/座',style: TextStyle(fontSize: zsp(16),color: Color(0xFFA2A2A2),fontWeight: FontWeight.normal),), ], ), ) ], crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, ), padding: EdgeInsets.all(hsp(20)), ) ], ), ); }, separatorBuilder: (context,index){ return Container( color: Colors.white, width: wsp(14), ); }, itemCount: (_dataArray[index]['dtAirTours']).length, padding: EdgeInsets.only(bottom: hsp(20)), ), ), ], ); }, separatorBuilder: (context,index){ return Divider(height: 10,thickness: 10,color: Color(0xFFF5F6F8),); }, itemCount: _dataArray.length, padding: EdgeInsets.all(0), shrinkWrap: true, physics: NeverScrollableScrollPhysics(), ), Container( height: 30, color: Color(0xFFF5F6F8), ) ], ), ), ), ); } _getFeatureDisplayShowData() async{ Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/featureDisplay/show',parameter: {},isLoading: false,isToken: false); if(dict!=null){ _banners = dict['data']['banner']; _products = dict['data']['product']; _advertising = dict['data']['advertising']; SharedPreferences prefer = await SharedPreferences.getInstance(); if(prefer.getString('cityHistory')!=null){ String historyStr = prefer.getString('cityHistory'); List historyList = jsonDecode(historyStr); _city = '${historyList[0]['display']}'; }else{ _city = ''; } setState(() { }); _getFeatureDisplayListData(_city); } } _getFeatureDisplayListData(String city) async { Map dict = await ysRequestHttp(context, type: requestType.get,api: '/app/applets/featureDisplay/list',parameter: {'city':city},isLoading: true,isToken: false); if (dict != null) { setState(() { _dataArray = dict['data']; }); } } }