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/YSContractPlaneDetail.dart'; import 'package:ysairplane2/code/YSShortDetail.dart'; import 'package:ysairplane2/tools/YSNetWorking.dart'; import 'package:ysairplane2/tools/YSTools.dart'; import '../YSMarryPlane.dart'; import '../YSSearchResult.dart'; class YSShopView extends StatefulWidget { final Map shop; final String location; final type; const YSShopView({Key key, @required this.shop, @required this.location, @required this.type}) : super(key: key); @override _YSShopViewState createState() => _YSShopViewState(); } class _YSShopViewState extends State { @override Widget build(BuildContext context) { return GestureDetector( onTap: (){ Navigator.of(context).push( CupertinoPageRoute(builder: (context){ return YSShop(shop: widget.shop,location: widget.location,); }) ); }, child: Container( margin: EdgeInsets.only(top: hsp(10)), padding: EdgeInsets.all(hsp(30)), color: Colors.white, child: LayoutBuilder( builder: (context,size){ return Row( children: [ Image.network(widget.shop['logo'],height: hsp(100),width: hsp(100),), Container( width: size.maxWidth-hsp(300), padding: EdgeInsets.only(left: hsp(20),right: hsp(20)), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(widget.shop['name'],style: TextStyle(fontSize: zsp(30), color: Colors.black,fontWeight: FontWeight.bold),), Text(widget.shop['address'],style: TextStyle(fontSize: zsp(28), color: Colors.grey,height: 2),) ], ), ), Container( height: hsp(60), width: hsp(200), decoration: BoxDecoration( color: Colors.redAccent, borderRadius: BorderRadius.all(Radius.circular(50)) ), alignment: Alignment.center, child: Text('进店逛逛',style: TextStyle(fontSize: zsp(26),color: Colors.white),), ) ], ); }, ), ), ); } } class YSShop extends StatefulWidget { final Map shop; final String location; final type; const YSShop({Key key, @required this.shop, @required this.location, @required this.type}) : super(key: key); @override _YSShopState createState() => _YSShopState(); } class _YSShopState extends State { int _page = 1; List _dataArray = []; int _titleIndex = 0; List _titles = ['综合','评分','价钱','距离']; Map _msgDict; String _cityStr = ''; @override void initState() { Future.delayed(Duration(seconds: 0)).then((value){ _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(450), 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(450), 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: widget.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(top: MediaQuery.of(context).padding.top+hsp(260)), height: hsp(200), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only(topRight: Radius.circular(10),topLeft: Radius.circular(10)) ), padding: EdgeInsets.only(left: hsp(30),right: hsp(30)), width: MediaQuery.of(context).size.width, child: Row( children: [ Image.network(widget.shop['logo'],height: hsp(100),width: hsp(100),), Container( width: MediaQuery.of(context).size.width-hsp(220), padding: EdgeInsets.only(left: hsp(20),right: hsp(20)), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text(widget.shop['name'],style: TextStyle(fontSize: zsp(30), color: Colors.black,fontWeight: FontWeight.bold),), Text(widget.shop['address'],style: TextStyle(fontSize: zsp(28), color: Colors.grey,height: 2),) ], ), ), ], ), ), Container( margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(430)), height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-hsp(350), width: MediaQuery.of(context).size.width, color: Colors.white, 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(510)-0.5, child: EasyRefresh( onRefresh: _refreshData, onLoad: _loadMoreData, header: TaurusHeader( ), footer: TaurusFooter( ), child: ListView.separated( itemBuilder: (context,index){ Map item = _dataArray[index]; return GestureDetector( behavior: HitTestBehavior.opaque, onTap: (){ Navigator.of(context).push( CupertinoPageRoute( builder: (context){ return item['type']==4||item['type']==5||item['type']==9?YSMarryPlane( marryId: item['id'],type: item['type'] ):item['type']==6?YSShortDetail( shortId: item['id'], ):YSContractPlaneDetail( contractId: item['id'], isWhole: item['type'], ); } ) ); }, child: Container( padding: EdgeInsets.all(hsp(30)), child: Row( children: [ Container( height: hsp(200), width: hsp(250), child: ysImageLoad( imageUrl: '${item['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('${item['title']}',style: TextStyle(fontSize: zsp(30),color: Color(0xFF343434)),maxLines: 2,), Text('${item['companyName']}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF9A9A9A)),), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('${item['modelNum']}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF9A9A9A)),), RichText( text: TextSpan( text: '¥', style: TextStyle(fontSize: zsp(24),color: Color(0xFFEB423B)), children: [ TextSpan( text: '${item['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), ), ), ), ], ), ), ], ), ), ); } Future _refreshData() async{ SharedPreferences preferences = await SharedPreferences.getInstance(); _cityStr = preferences.getString('location'); _page = 1; Map request = {}; request['partnerId'] = widget.shop['partnerId']; request['pageNo'] = _page; request['type'] = 4-_titleIndex; request['location'] = widget.location; Map dict = await ysRequestHttp(context,type: requestType.get, api: '/app/applets/AirTour/partner_list',parameter: request,isLoading: false,isToken: true); if(dict!=null){ _msgDict = dict['partnerHome']; _dataArray = dict['data']['resultList']; setState(() {}); } } Future _loadMoreData() async{ _page++; Map request = {}; request['partnerId'] = widget.shop['partnerId']; request['pageNo'] = _page; request['type'] = 4-_titleIndex; request['location'] = widget.location; Map dict = await ysRequestHttp(context,type: requestType.get, api: '/app/applets/AirTour/partner_list',parameter: request,isLoading: false,isToken: true); if(dict!=null){ _dataArray.addAll(dict['data']['resultList']); setState(() {}); } } }