| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082 |
- import 'dart:async';
- import 'dart:convert';
- import 'dart:math';
- import 'package:address_picker/address_picker.dart';
- import 'package:amap_flutter_base/amap_flutter_base.dart';
- import 'package:bbyyy/beans/commodity_category_bean_entity.dart';
- import 'package:bbyyy/beans/goods_bean_entity.dart';
- import 'package:bbyyy/beans/home_carousel_bean_entity.dart';
- import 'package:bbyyy/beans/my_shop_bean_entity.dart';
- import 'package:bbyyy/beans/store_bean_entity.dart';
- import 'package:bbyyy/https/MyDio.dart';
- import 'package:bbyyy/https/my_request.dart';
- import 'package:bbyyy/https/url.dart';
- import 'package:bbyyy/my_tools/const.dart';
- import 'package:bbyyy/my_tools/dims.dart';
- import 'package:bbyyy/my_tools/event_bus.dart';
- import 'package:bbyyy/my_tools/my_colors.dart';
- import 'package:bbyyy/my_tools/my_cookie.dart';
- import 'package:bbyyy/my_tools/my_tools.dart';
- import 'package:bbyyy/my_tools/my_views.dart';
- import 'package:bbyyy/my_tools/providers.dart';
- import 'package:bbyyy/paegs/gang_page/gang_in_page/scan_page/scan_page.dart';
- import 'package:bbyyy/paegs/home_page/qr_code_payment/new_qr_code_payment_page.dart';
- import 'package:bbyyy/paegs/home_page/qr_code_payment/qr_code_payment_page.dart';
- import 'package:bbyyy/paegs/home_page/recommended_today_page.dart';
- import 'package:bbyyy/paegs/root_page/root_page_view.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_svg/flutter_svg.dart';
- import 'package:flutter_swiper/flutter_swiper.dart';
- import 'package:get/get.dart';
- import 'package:provider/src/provider.dart';
- import 'package:pull_to_refresh/pull_to_refresh.dart';
- class HomePage extends StatefulWidget {
- @override
- _HomePageState createState() => _HomePageState();
- }
- class _HomePageState extends State<HomePage>
- with AutomaticKeepAliveClientMixin {
- var data = [];
- var container = [];
- var puShop = [];
- var imgs = ['images/banner1.png', 'images/banner2.png', 'images/banner3.png'];
- var netImgs = [];
- int selectedIndex = 0;
- var tabs = ['全部'];
- var types = ['货帮', '货品'];
- List<DropdownMenuItem<String>> sortItems = [];
- int typeIndex = 1;
- List<MyShopBeanDataData> shops = [];
- ScrollController _controller = ScrollController();
- double maxH;
- double minH = 164;
- double H = 0;
- bool showInput = false;
- TextEditingController _description = TextEditingController();
- FocusNode _descriptionFocus = FocusNode();
- RefreshController _reController = RefreshController(initialRefresh: true);
- int page = 1;
- int pageIndex = 0;
- bool showS = false;
- String province;
- String city;
- Address _address;
- @override
- void initState() {
- super.initState();
- EventBus().on('commodity_category', (arg) {
- setState(() {});
- });
- EventBus().on('uploadGoods', (arg) {
- _reController.requestRefresh();
- });
- EventBus().on('toTop', (arg) {
- _controller.animateTo(0.0,
- duration: Duration(milliseconds: 200), curve: Curves.easeIn);
- });
- EventBus().on('homeCarousel', (arg) {
- if (arg is HomeCarouselBeanEntity) {
- arg.data.forEach((element) {
- netImgs.add(element.path);
- });
- setState(() {});
- }
- });
- EventBus().on('商品变动', (arg) {
- _reController.requestRefresh();
- });
- EventBus().on('getLocation', (arg) {
- if (MyCookie().location.province == '四川省' &&
- MyCookie().location.city == '成都市') {
- return;
- }
- _reController.requestRefresh();
- setState(() {});
- });
- _controller.addListener(() {
- setState(() {
- if (_controller.offset == 0) {
- RootPageView().toTop = false;
- EventBus().emit('ChangePage');
- } else {
- RootPageView().toTop = true;
- EventBus().emit('ChangePage');
- }
- H = maxH - _controller.offset;
- if (H < minH) {
- H = minH;
- } else if (H > maxH) {
- H = maxH;
- }
- });
- });
- types.forEach((element) {
- sortItems.add(DropdownMenuItem(
- child: Text(
- element,
- style: TextStyle(color: MyColors.c666666, fontSize: 14),
- ),
- value: element,
- ));
- });
- _descriptionFocus.addListener(() {
- if (_descriptionFocus.hasFocus) {
- } else {
- if (_description.text.isEmpty) {
- showInput = false;
- }
- }
- });
- homeCarousel();
- }
- @override
- void dispose() {
- // TODO: implement dispose
- super.dispose();
- EventBus().off('commodity_category');
- EventBus().off('uploadGoods');
- EventBus().off('toTop');
- EventBus().off('homeCarousel');
- EventBus().off('商品变动');
- EventBus().off('getLocation');
- }
- @override
- Widget build(BuildContext context) {
- maxH = MediaQuery.of(context).size.width * (520 / 750);
- minH = MediaQuery.of(context).padding.top + 64;
- if (H == 0) {
- H = maxH;
- }
- return GestureDetector(
- onTap: () {
- MyTools().hideKeyboard(context);
- },
- behavior: HitTestBehavior.translucent,
- child: Scaffold(
- resizeToAvoidBottomInset: false,
- body: SmartRefresher(
- controller: _reController,
- onRefresh: onRefresh,
- onLoading: onLoading,
- enablePullDown: true,
- enablePullUp: true,
- child: CustomScrollView(
- slivers: [
- carouselAndSearch(context),
- // recommendedToday(),
- storeCategory(),
- shopList()
- ],
- ),
- ),
- ),
- );
- }
- Widget shopList() {
- return SliverList(
- delegate: SliverChildBuilderDelegate(
- (c, index) {
- return MyViews().pubShopItem(puShop[index], context);
- },
- childCount: puShop.length,
- ));
- }
- Widget storeCategory() {
- return SliverPersistentHeader(
- pinned: true, //是否固定在顶部
- floating: false,
- delegate: _SliverAppBarDelegate(
- minHeight: 54,
- maxHeight: 54,
- child: Column(
- children: [
- Container(
- color: Colors.white,
- height: 53,
- child: ListView.builder(
- padding: EdgeInsets.only(left: 12, right: 12),
- itemBuilder: (c, index) {
- return GestureDetector(
- onTap: () {
- setState(() {
- selectedIndex = index;
- _reController.requestRefresh();
- });
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- padding:
- EdgeInsets.only(right: 15, left: 15, bottom: 9),
- child: Column(
- children: [
- Text(
- tabs[index],
- style: TextStyle(
- color: index == selectedIndex
- ? MyColors.cFF4233
- : MyColors.c666666,
- fontSize: 14),
- ),
- Container(
- height: 10,
- child: Visibility(
- child: SvgPicture.asset('images/svg/tab.svg'),
- visible: index == selectedIndex,
- ),
- )
- ],
- mainAxisAlignment: MainAxisAlignment.end,
- ),
- height: 53,
- ),
- );
- },
- itemCount: tabs.length,
- scrollDirection: Axis.horizontal,
- ),
- ),
- Container(
- height: 1,
- color: MyColors.cf2f2f2,
- ),
- ],
- )));
- }
- Widget recommendedToday() {
- return SliverToBoxAdapter(
- child: Column(
- children: [
- Container(
- padding: EdgeInsets.only(left: 16, right: 10),
- height: 54,
- child: Row(
- children: [
- Text(
- '梆梆今日折扣',
- style: TextStyle(color: MyColors.c333333, fontSize: 14),
- ),
- GestureDetector(
- onTap: () {
- MyTools()
- .toPage(context, RecommendedTodayPage(), (then) {});
- },
- behavior: HitTestBehavior.translucent,
- child: Row(
- children: [
- Text(
- '查看更多',
- style: TextStyle(color: MyColors.c666666, fontSize: 12),
- ),
- Icon(
- Icons.chevron_right,
- color: MyColors.c666666,
- )
- ],
- ),
- )
- ],
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- ),
- ),
- Container(
- height: 1,
- color: MyColors.cf2f2f2,
- ),
- Container(
- height: 168,
- child: ListView.builder(
- padding: EdgeInsets.symmetric(horizontal: 16, vertical: 15),
- itemBuilder: (c, index) {
- return Container(
- margin: EdgeInsets.only(right: 10),
- height: 138,
- width: 100,
- padding: EdgeInsets.all(5),
- decoration: BoxDecoration(
- boxShadow: [
- BoxShadow(
- color: MyColors.c7FE1E1E1,
- blurRadius: 5.0,
- ),
- ],
- color: Colors.white,
- borderRadius: BorderRadius.circular(4),
- ),
- child: Column(
- children: [
- MyViews().netImg('', 90, 90,
- placeholder: 'images/svg/goodsDefImg.svg'),
- Text(
- '8.9元充10元话费',
- style: TextStyle(color: MyColors.c333333, fontSize: 11),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- softWrap: true,
- ),
- Row(
- children: [
- Text(
- '¥8.90',
- style: TextStyle(
- color: MyColors.cFF4233,
- fontSize: 13,
- fontWeight: FontWeight.bold),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- softWrap: true,
- ),
- Container(
- decoration: BoxDecoration(
- border:
- Border.all(color: MyColors.cFF4233, width: 1),
- borderRadius: BorderRadius.circular(7),
- ),
- height: 14,
- width: 30,
- child: Text(
- '详情',
- style: TextStyle(
- color: MyColors.cFF4233, fontSize: 9),
- ),
- alignment: Alignment.center,
- )
- ],
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- )
- ],
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- crossAxisAlignment: CrossAxisAlignment.start,
- ),
- );
- },
- itemCount: 10,
- scrollDirection: Axis.horizontal,
- ),
- ),
- ],
- ),
- );
- }
- Widget carouselAndSearch(BuildContext context) {
- return SliverPersistentHeader(
- pinned: true,
- floating: false,
- delegate: _SliverAppBarDelegate(
- minHeight: minH,
- maxHeight: maxH,
- child: Stack(
- children: [
- Swiper(
- itemBuilder: (BuildContext context, int index) {
- return netImgs.length == 0
- ? GestureDetector(
- onTap: () {
- // EventBus().emit('showRP');
- },
- child: Image.asset(
- "${imgs[index]}",
- fit: BoxFit.cover,
- ),
- )
- : MyViews().netImg(imgURL(netImgs[index]), H,
- MediaQuery.of(context).size.width,
- placeholder: 'images/svg/goodsDefImg.svg');
- },
- itemCount: netImgs.length == 0 ? imgs.length : netImgs.length,
- viewportFraction: 1,
- scale: 1,
- autoplay: true,
- ),
- SafeArea(
- bottom: false,
- child: Stack(
- children: [
- Positioned(
- left: 0,
- child: Container(
- padding: EdgeInsets.only(left: 10, right: 10, top: 12),
- child: GestureDetector(
- onTap: () {
- addressSelection();
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- padding: EdgeInsets.only(left: 11, right: 14),
- decoration: BoxDecoration(
- boxShadow: [
- BoxShadow(
- color: MyColors.c7FE1E1E1,
- blurRadius: 5.0,
- ),
- ],
- color: Colors.white,
- borderRadius: BorderRadius.circular(20)),
- child: Row(
- children: [
- Icon(
- Icons.location_on_rounded,
- color: MyColors.c333333,
- size: 20,
- ),
- Text(
- province == null
- ? MyCookie().location != null
- ? MyCookie().location.city
- : '成都市'
- : city,
- style: TextStyle(
- color: MyColors.c333333,
- fontSize: 12,
- fontWeight: FontWeight.bold),
- ),
- ],
- ),
- height: 40,
- alignment: Alignment.center,
- ),
- ),
- alignment: Alignment.center,
- ),
- ),
- Positioned(
- top: 0,
- right: 50,
- child: Container(
- padding: EdgeInsets.only(left: 10, right: 10, top: 12),
- child: GestureDetector(
- onTap: () {
- showS = !showS;
- if (!showS) {
- _description.clear();
- }
- setState(() {});
- },
- behavior: HitTestBehavior.translucent,
- child: AnimatedContainer(
- height: 40,
- width: !showS
- ? 40
- : MediaQuery.of(context).size.width - 70,
- child: Row(
- children: [
- SvgPicture.asset(
- showS
- ? 'images/svg/箭头.svg'
- : 'images/svg/搜索.svg',
- height: 15,
- width: 15,
- color: MyColors.cFF4233,
- ),
- Visibility(
- visible: showS,
- child: Expanded(
- child: TextField(
- controller: _description,
- cursorColor: MyColors.cFF4233,
- cursorWidth: 1.0,
- onTap: () {},
- decoration: InputDecoration(
- border: InputBorder.none,
- disabledBorder: InputBorder.none,
- enabledBorder: InputBorder.none,
- focusedBorder: InputBorder.none,
- isDense: true,
- hintText: '请输入...',
- hintStyle: TextStyle(
- color: MyColors.c999999,
- fontSize: 16),
- contentPadding:
- const EdgeInsets.fromLTRB(
- 14, 4.5, 8, 4.5),
- ),
- maxLines: 1,
- style: TextStyle(
- color: MyColors.c333333,
- fontSize: 16,
- height: 1.3,
- letterSpacing: 0.2),
- keyboardType: TextInputType.text,
- onChanged: (t) {
- setState(() {});
- },
- ),
- ),
- ),
- Visibility(
- visible:
- showS && _description.text.isNotEmpty,
- child: GestureDetector(
- onTap: () {
- MyTools().hideKeyboard(context);
- _reController.requestRefresh();
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- child: MyViews()
- .myText('搜索', Colors.white, 13),
- decoration: BoxDecoration(
- color: MyColors.cFF4233,
- borderRadius: BorderRadius.circular(20),
- ),
- height: 40,
- width: 80,
- alignment: Alignment.center,
- ),
- ),
- )
- ],
- mainAxisAlignment: MainAxisAlignment.center,
- ),
- alignment: !showS
- ? Alignment.center
- : Alignment.centerLeft,
- padding: EdgeInsets.only(left: !showS ? 0 : 12),
- decoration: BoxDecoration(
- borderRadius:
- BorderRadius.all(Radius.circular(20)),
- color: Colors.white,
- ),
- duration: Duration(milliseconds: 200),
- ),
- ),
- alignment: Alignment.centerRight,
- ),
- ),
- Positioned(
- top: 0,
- right: 0,
- child: GestureDetector(
- onTap: () {
- MyTools().toPage(context, ScanPage(), (then) {
- if (then is String) {
- if (then.isNotEmpty && then != null) {
- Timer(Duration(milliseconds: 200), () {
- if (then.contains(
- 'https://bby.banghuo.net/pay.html?shop_uid=')) {
- } else {
- showToast('暂不支持该二维码');
- return;
- }
- MyTools().hideKeyboard(context);
- int shopUid = int.parse(then.split('=')[1]);
- print(shopUid);
- MyTools().toPage(context, NewPayToTheGangPage(shopUid,orderTypeOfflinePay), (then){});
- });
- }
- }
- });
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- margin: EdgeInsets.only(left: 10, right: 10, top: 12),
- height: 40,
- width: 40,
- child: SvgPicture.asset(
- 'images/svg/扫一扫_icon.svg',
- color: MyColors.cFF4233,
- height: 18,
- width: 18,
- ),
- alignment: Alignment.center,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(20),
- color: Colors.white),
- ),
- ),
- )
- ],
- ),
- ),
- ],
- )),
- );
- }
- @override
- // TODO: implement wantKeepAlive
- bool get wantKeepAlive => true;
- void getGoods(List<dynamic> shopUID) {
- var qData;
- if (shopUID.length == 0) {
- var conditions = ["public == true", "on_sale == true"];
- if (selectedIndex != 0) {
- conditions.add("category == ${tabs[selectedIndex]}");
- }
- if (_description.text.isNotEmpty) {
- conditions.add('title LIKE ${_description.text.toString()}');
- }
- qData = {
- "key": "commodity",
- "filters": {"conditions": conditions},
- "dims": commodityDims,
- "order_by": ["id,desc", "no,desc"],
- "paging": [page, 20]
- };
- } else {
- var conditions = ["shop_uid in $shopUID", "on_sale == true"];
- var conditions2 = ["public == true", "on_sale == true"];
- if (selectedIndex != 0) {
- conditions.add("category == ${tabs[selectedIndex]}");
- conditions2.add("category == ${tabs[selectedIndex]}");
- }
- if (_description.text.isNotEmpty) {
- conditions.add('title LIKE ${_description.text.toString()}');
- conditions2.add('title LIKE ${_description.text.toString()}');
- }
- qData = {
- "key": "commodity",
- "filters": {
- "or": true,
- "conditions": conditions,
- "filters": [
- {"conditions": conditions2}
- ]
- },
- "order_by": ["id,desc", "no,desc"],
- "dims": commodityDims,
- "paging": [page, 20]
- };
- }
- MyDio().query(qData, (response, hasError) {
- if (!hasError) {
- GoodsBeanEntity entity =
- GoodsBeanEntity().fromJson(json.decode(response.data.toString()));
- container.clear();
- container.addAll(entity.data.data);
- }
- queryAd();
- }, (error) {
- queryAd();
- });
- }
- void onRefresh() {
- page = 1;
- if (pageIndex == 1) {
- initTabs();
- findAStore();
- } else {
- storeType();
- checkPublicStores();
- }
- }
- void onLoading() {
- page++;
- if (pageIndex == 1) {
- findAStore();
- } else {
- checkPublicStores();
- }
- }
- Future<void> initTabs() async {
- List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
- MyDio().query({
- "key": "commodity_category",
- "filters": {},
- "dims": [
- "name",
- ]
- }, (response, hasError) {
- if (!hasError) {
- try {
- CommodityCategoryBeanEntity entity = CommodityCategoryBeanEntity()
- .fromJson(json.decode(response.data.toString()));
- commodityCategoryBeanData = entity.data;
- tabs.clear();
- tabs.add('全部');
- commodityCategoryBeanData.forEach((element) {
- tabs.insert(1, element.name);
- });
- if (selectedIndex > tabs.length - 1) {
- selectedIndex = 0;
- }
- setState(() {});
- } catch (e) {
- tabs.clear();
- tabs.add('全部');
- if (selectedIndex > tabs.length - 1) {
- selectedIndex = 0;
- }
- }
- } else {
- return commodityCategoryBeanData;
- }
- }, (error) {
- return commodityCategoryBeanData;
- });
- }
- findAStore() {
- MyDio().query({
- "key": "shop_user",
- "filters": {
- "or": true,
- "conditions": [
- "role!=$shopUserOwner",
- "user_uid==${MyCookie().getUID()}",
- "review_state==1"
- ],
- "filters": [
- {
- "conditions": [
- "role==$shopUserOwner",
- "user_uid==${MyCookie().getUID()}"
- ]
- }
- ]
- },
- "dims": shopUserDims,
- "paging": [1, 20000]
- }, (response, hasError) {
- if (!hasError) {
- MyShopBeanEntity entity =
- MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
- shops = entity.data.data;
- var shopUID = [];
- shops.forEach((element) {
- shopUID.add(element.shopUid);
- });
- getGoods(shopUID);
- }
- }, (error) {});
- }
- queryAd() {
- if (page == 1) {
- data.clear();
- puShop.clear();
- }
- if (pageIndex == 1) {
- data.addAll(container);
- } else {
- puShop.addAll(container);
- if(MyCookie().location!=null){
- puShop.forEach((element) {
- try{
- if(element is StoreBeanDataData&&element.longitude != 0 ){
- element.distance = balanceDisplay(AMapTools.distanceBetween(LatLng(element.latitude, element.longitude), LatLng(MyCookie().location.latitude, MyCookie().location.longitude)) / 1000);
- print('element.distance------${element.distance}');
- }
- }catch(e){
- print('element.distance------$e');
- }
- });
- puShop.sort((e1,e2){
- if(e1 is StoreBeanDataData&&e1.distance!=null&&e2 is StoreBeanDataData&&e2.distance!=null){
- return e1.distance.compareTo(e2.distance);
- }else if(e1 is StoreBeanDataData&&e1.distance==null&&e2 is StoreBeanDataData&&e2.distance!=null){
- return 1;
- }else if(e1 is StoreBeanDataData&&e1.distance!=null&&e2 is StoreBeanDataData&&e2.distance==null){
- return -1;
- }else{
- return 0;
- }
- });
- }else{
- EventBus().on('getLocation', (arg) {
- puShop.forEach((element) {
- try{
- if(element is StoreBeanDataData&&element.longitude != 0 ){
- element.distance = balanceDisplay(AMapTools.distanceBetween(LatLng(element.latitude, element.longitude), LatLng(MyCookie().location.latitude, MyCookie().location.longitude)) / 1000);
- print('element.distance------${element.distance}');
- }
- }catch(e){
- print('element.distance------$e');
- }
- });
- puShop.sort((e1,e2){
- if(e1 is StoreBeanDataData&&e1.distance!=null&&e2 is StoreBeanDataData&&e2.distance!=null){
- return e1.distance.compareTo(e2.distance);
- }else if(e1 is StoreBeanDataData&&e1.distance==null&&e2 is StoreBeanDataData&&e2.distance!=null){
- return 1;
- }else if(e1 is StoreBeanDataData&&e1.distance!=null&&e2 is StoreBeanDataData&&e2.distance==null){
- return -1;
- }else{
- return 0;
- }
- });
- });
- }
- }
- setState(() {});
- endRe(_reController);
- return;
- // int count = 5;
- // MyDio().query({
- // "key": "ad",
- // "filters": {
- // "conditions": ['on_show == true']
- // },
- // "dims": adDims,
- // "order_by": ["id,desc", "no,desc"],
- // "paging": [page, count]
- // }, (response, hasError) {
- // if (!hasError) {
- // AdBeanEntity entity =
- // AdBeanEntity().fromJson(json.decode(response.data.toString()));
- // container.addAll(entity.data.data);
- // container.shuffle();
- // }
- // if (page == 1) {
- // data.clear();
- // puShop.clear();
- // }
- // if (pageIndex == 1) {
- // data.addAll(container);
- // } else {
- // puShop.addAll(container);
- // }
- // setState(() {});
- // endRe(_reController);
- // }, (error) {
- // if (page == 1) {
- // data.clear();
- // }
- // data.addAll(container);
- // setState(() {});
- // endRe(_reController);
- // });
- }
- void checkPublicStores() {
- var conditions = ['private==false', 'state == $shopStateNormal'];
- if (selectedIndex != 0) {
- conditions.add("category == ${tabs[selectedIndex]}");
- }
- if (_description.text.isNotEmpty) {
- conditions.add('name LIKE ${_description.text.toString()}');
- }
- if (MyCookie().location == null && province == null) {
- conditions.add('province == 四川省');
- conditions.add('city == 成都市');
- } else {
- if (province != null) {
- conditions.add('province == $province');
- conditions.add('city == $city');
- } else if (MyCookie().location != null) {
- conditions.add('province == ${MyCookie().location.province}');
- conditions.add('city == ${MyCookie().location.city}');
- }
- }
- MyDio().query({
- "key": "shop",
- "filters": {"conditions": conditions},
- "dims": shopDims,
- "order_by": ["id,desc", "no,desc"],
- "paging": [page, 20]
- }, (response, hasError) {
- if (!hasError) {
- StoreBeanEntity entity =
- StoreBeanEntity().fromJson(json.decode(response.data.toString()));
- container.clear();
- container.addAll(entity.data.data);
- }
- queryAd();
- }, (error) {
- queryAd();
- });
- }
- void storeType() {
- List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
- MyDio().query({
- "key": "shop_category",
- "filters": {},
- "dims": [
- "name",
- ]
- }, (response, hasError) {
- if (!hasError) {
- try {
- CommodityCategoryBeanEntity entity = CommodityCategoryBeanEntity()
- .fromJson(json.decode(response.data.toString()));
- commodityCategoryBeanData = entity.data;
- tabs.clear();
- tabs.add('全部');
- commodityCategoryBeanData.forEach((element) {
- tabs.insert(1, element.name);
- });
- setState(() {});
- } catch (e) {
- tabs.clear();
- tabs.add('全部');
- if (selectedIndex > tabs.length - 1) {
- selectedIndex = 0;
- }
- setState(() {});
- }
- }
- }, (error) {});
- }
- void addressSelection() {
- StateSetter ss;
- showModalBottomSheet(
- context: context,
- builder: (context) => BottomSheet(
- onClosing: () {},
- builder: (context) => Container(
- height: 350,
- child: Column(
- children: [
- StatefulBuilder(
- builder: (c, s) {
- ss = s;
- return Container(
- height: 40,
- color: Colors.white,
- padding: EdgeInsets.symmetric(horizontal: 15),
- child: Row(
- children: [
- Row(
- children: [
- Text(
- '定位到: ',
- style: TextStyle(
- color: MyColors.cFF4233, fontSize: 14),
- ),
- Text(
- _address == null
- ? '北京市 北京市'
- : '${_address.currentProvince.province} ${_address.currentCity.city}',
- style: TextStyle(
- color: MyColors.cFF4233, fontSize: 14),
- ),
- ],
- ),
- GestureDetector(
- child: Container(
- height: 40,
- width: 60,
- alignment: Alignment.center,
- child: Text(
- '确定',
- style: TextStyle(
- color: MyColors.cFF4233, fontSize: 16),
- ),
- ),
- onTap: () {
- if (_address == null) {
- province = '北京市';
- city = '北京市';
- setState(() {});
- _reController.requestRefresh();
- _address = null;
- Navigator.pop(context);
- } else {
- province = _address.currentProvince.province;
- city = _address.currentCity.city;
- setState(() {});
- _reController.requestRefresh();
- _address = null;
- Navigator.pop(context);
- }
- },
- behavior: HitTestBehavior.translucent,
- ),
- ],
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- ),
- );
- },
- ),
- GestureDetector(
- onTap: () {
- if (MyCookie().location != null) {
- province = MyCookie().location.province;
- city = MyCookie().location.city;
- setState(() {});
- _reController.requestRefresh();
- _address = null;
- Navigator.pop(context);
- }
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- height: 60,
- color: Colors.white,
- padding: EdgeInsets.symmetric(horizontal: 20),
- child: Row(
- children: [
- Text(
- '当前定位:',
- style: TextStyle(color: MyColors.c333333, fontSize: 16),
- ),
- Text(
- MyCookie().location != null
- ? '${MyCookie().location.province} ${MyCookie().location.city}'
- : '请开启定位权限',
- style: TextStyle(color: MyColors.c333333, fontSize: 16),
- )
- ],
- ),
- ),
- ),
- Container(
- height: 250.0,
- child: AddressPicker(
- style: TextStyle(color: Colors.black, fontSize: 17),
- mode: AddressPickerMode.provinceAndCity,
- onSelectedAddressChanged: (address) {
- _address = address;
- ss(() {});
- },
- ),
- ),
- ],
- ),
- ),
- ),
- );
- }
- }
- class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
- _SliverAppBarDelegate({
- @required this.minHeight,
- @required this.maxHeight,
- @required this.child,
- });
- final double minHeight;
- final double maxHeight;
- final Widget child;
- @override
- double get minExtent => minHeight;
- @override
- double get maxExtent => max(maxHeight, minHeight);
- @override
- Widget build(
- BuildContext context, double shrinkOffset, bool overlapsContent) {
- return new SizedBox.expand(child: child);
- }
- @override
- bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {
- return maxHeight != oldDelegate.maxHeight ||
- minHeight != oldDelegate.minHeight ||
- child != oldDelegate.child;
- }
- }
|