home_page.dart 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'dart:math';
  4. import 'package:address_picker/address_picker.dart';
  5. import 'package:bbyyy/beans/commodity_category_bean_entity.dart';
  6. import 'package:bbyyy/beans/goods_bean_entity.dart';
  7. import 'package:bbyyy/beans/home_carousel_bean_entity.dart';
  8. import 'package:bbyyy/beans/my_shop_bean_entity.dart';
  9. import 'package:bbyyy/beans/store_bean_entity.dart';
  10. import 'package:bbyyy/https/MyDio.dart';
  11. import 'package:bbyyy/https/my_request.dart';
  12. import 'package:bbyyy/https/url.dart';
  13. import 'package:bbyyy/my_tools/const.dart';
  14. import 'package:bbyyy/my_tools/dims.dart';
  15. import 'package:bbyyy/my_tools/event_bus.dart';
  16. import 'package:bbyyy/my_tools/my_colors.dart';
  17. import 'package:bbyyy/my_tools/my_cookie.dart';
  18. import 'package:bbyyy/my_tools/my_tools.dart';
  19. import 'package:bbyyy/my_tools/my_views.dart';
  20. import 'package:bbyyy/paegs/gang_page/gang_in_page/scan_page/scan_page.dart';
  21. import 'package:bbyyy/paegs/home_page/qr_code_payment/new_qr_code_payment_page.dart';
  22. import 'package:bbyyy/paegs/home_page/qr_code_payment/qr_code_payment_page.dart';
  23. import 'package:bbyyy/paegs/home_page/recommended_today_page.dart';
  24. import 'package:bbyyy/paegs/root_page/root_page_view.dart';
  25. import 'package:flutter/cupertino.dart';
  26. import 'package:flutter/material.dart';
  27. import 'package:flutter_svg/flutter_svg.dart';
  28. import 'package:flutter_swiper/flutter_swiper.dart';
  29. import 'package:get/get.dart';
  30. import 'package:pull_to_refresh/pull_to_refresh.dart';
  31. class HomePage extends StatefulWidget {
  32. @override
  33. _HomePageState createState() => _HomePageState();
  34. }
  35. class _HomePageState extends State<HomePage>
  36. with AutomaticKeepAliveClientMixin {
  37. var data = [];
  38. var container = [];
  39. var puShop = [];
  40. var imgs = ['images/banner1.png', 'images/banner2.png', 'images/banner3.png'];
  41. var netImgs = [];
  42. int selectedIndex = 0;
  43. var tabs = ['全部'];
  44. var types = ['货帮', '货品'];
  45. List<DropdownMenuItem<String>> sortItems = [];
  46. int typeIndex = 1;
  47. List<MyShopBeanDataData> shops = [];
  48. ScrollController _controller = ScrollController();
  49. double maxH;
  50. double minH = 164;
  51. double H = 0;
  52. bool showInput = false;
  53. TextEditingController _description = TextEditingController();
  54. FocusNode _descriptionFocus = FocusNode();
  55. RefreshController _reController = RefreshController(initialRefresh: true);
  56. int page = 1;
  57. int pageIndex = 0;
  58. bool showS = false;
  59. String province;
  60. String city;
  61. Address _address;
  62. @override
  63. void initState() {
  64. super.initState();
  65. EventBus().on('commodity_category', (arg) {
  66. setState(() {});
  67. });
  68. EventBus().on('uploadGoods', (arg) {
  69. _reController.requestRefresh();
  70. });
  71. EventBus().on('toTop', (arg) {
  72. _controller.animateTo(0.0,
  73. duration: Duration(milliseconds: 200), curve: Curves.easeIn);
  74. });
  75. EventBus().on('homeCarousel', (arg) {
  76. if (arg is HomeCarouselBeanEntity) {
  77. arg.data.forEach((element) {
  78. netImgs.add(element.path);
  79. });
  80. setState(() {});
  81. }
  82. });
  83. EventBus().on('商品变动', (arg) {
  84. _reController.requestRefresh();
  85. });
  86. EventBus().on('getLocation', (arg) {
  87. if (MyCookie().location.province == '四川省' &&
  88. MyCookie().location.city == '成都市') {
  89. return;
  90. }
  91. _reController.requestRefresh();
  92. setState(() {});
  93. });
  94. _controller.addListener(() {
  95. setState(() {
  96. if (_controller.offset == 0) {
  97. RootPageView().toTop = false;
  98. EventBus().emit('ChangePage');
  99. } else {
  100. RootPageView().toTop = true;
  101. EventBus().emit('ChangePage');
  102. }
  103. H = maxH - _controller.offset;
  104. if (H < minH) {
  105. H = minH;
  106. } else if (H > maxH) {
  107. H = maxH;
  108. }
  109. });
  110. });
  111. types.forEach((element) {
  112. sortItems.add(DropdownMenuItem(
  113. child: Text(
  114. element,
  115. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  116. ),
  117. value: element,
  118. ));
  119. });
  120. _descriptionFocus.addListener(() {
  121. if (_descriptionFocus.hasFocus) {
  122. } else {
  123. if (_description.text.isEmpty) {
  124. showInput = false;
  125. }
  126. }
  127. });
  128. homeCarousel();
  129. }
  130. @override
  131. void dispose() {
  132. // TODO: implement dispose
  133. super.dispose();
  134. EventBus().off('commodity_category');
  135. EventBus().off('uploadGoods');
  136. EventBus().off('toTop');
  137. EventBus().off('homeCarousel');
  138. EventBus().off('商品变动');
  139. EventBus().off('getLocation');
  140. }
  141. @override
  142. Widget build(BuildContext context) {
  143. maxH = MediaQuery.of(context).size.width * (520 / 750);
  144. minH = MediaQuery.of(context).padding.top + 64;
  145. if (H == 0) {
  146. H = maxH;
  147. }
  148. return GestureDetector(
  149. onTap: () {
  150. MyTools().hideKeyboard(context);
  151. },
  152. behavior: HitTestBehavior.translucent,
  153. child: Scaffold(
  154. resizeToAvoidBottomInset: false,
  155. body: SmartRefresher(
  156. controller: _reController,
  157. onRefresh: onRefresh,
  158. onLoading: onLoading,
  159. enablePullDown: true,
  160. enablePullUp: true,
  161. child: CustomScrollView(
  162. slivers: [
  163. carouselAndSearch(context),
  164. // recommendedToday(),
  165. storeCategory(),
  166. shopList()
  167. ],
  168. ),
  169. ),
  170. ),
  171. );
  172. }
  173. Widget shopList() {
  174. return SliverList(
  175. delegate: SliverChildBuilderDelegate(
  176. (c, index) {
  177. return MyViews().pubShopItem(puShop[index], context);
  178. },
  179. childCount: puShop.length,
  180. ));
  181. }
  182. Widget storeCategory() {
  183. return SliverPersistentHeader(
  184. pinned: true, //是否固定在顶部
  185. floating: false,
  186. delegate: _SliverAppBarDelegate(
  187. minHeight: 54,
  188. maxHeight: 54,
  189. child: Column(
  190. children: [
  191. Container(
  192. color: Colors.white,
  193. height: 53,
  194. child: ListView.builder(
  195. padding: EdgeInsets.only(left: 12, right: 12),
  196. itemBuilder: (c, index) {
  197. return GestureDetector(
  198. onTap: () {
  199. setState(() {
  200. selectedIndex = index;
  201. _reController.requestRefresh();
  202. });
  203. },
  204. behavior: HitTestBehavior.translucent,
  205. child: Container(
  206. padding:
  207. EdgeInsets.only(right: 15, left: 15, bottom: 9),
  208. child: Column(
  209. children: [
  210. Text(
  211. tabs[index],
  212. style: TextStyle(
  213. color: index == selectedIndex
  214. ? MyColors.cFF4233
  215. : MyColors.c666666,
  216. fontSize: 14),
  217. ),
  218. Container(
  219. height: 10,
  220. child: Visibility(
  221. child: SvgPicture.asset('images/svg/tab.svg'),
  222. visible: index == selectedIndex,
  223. ),
  224. )
  225. ],
  226. mainAxisAlignment: MainAxisAlignment.end,
  227. ),
  228. height: 53,
  229. ),
  230. );
  231. },
  232. itemCount: tabs.length,
  233. scrollDirection: Axis.horizontal,
  234. ),
  235. ),
  236. Container(
  237. height: 1,
  238. color: MyColors.cf2f2f2,
  239. ),
  240. ],
  241. )));
  242. }
  243. Widget recommendedToday() {
  244. return SliverToBoxAdapter(
  245. child: Column(
  246. children: [
  247. Container(
  248. padding: EdgeInsets.only(left: 16, right: 10),
  249. height: 54,
  250. child: Row(
  251. children: [
  252. Text(
  253. '梆梆今日折扣',
  254. style: TextStyle(color: MyColors.c333333, fontSize: 14),
  255. ),
  256. GestureDetector(
  257. onTap: () {
  258. MyTools()
  259. .toPage(context, RecommendedTodayPage(), (then) {});
  260. },
  261. behavior: HitTestBehavior.translucent,
  262. child: Row(
  263. children: [
  264. Text(
  265. '查看更多',
  266. style: TextStyle(color: MyColors.c666666, fontSize: 12),
  267. ),
  268. Icon(
  269. Icons.chevron_right,
  270. color: MyColors.c666666,
  271. )
  272. ],
  273. ),
  274. )
  275. ],
  276. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  277. ),
  278. ),
  279. Container(
  280. height: 1,
  281. color: MyColors.cf2f2f2,
  282. ),
  283. Container(
  284. height: 168,
  285. child: ListView.builder(
  286. padding: EdgeInsets.symmetric(horizontal: 16, vertical: 15),
  287. itemBuilder: (c, index) {
  288. return Container(
  289. margin: EdgeInsets.only(right: 10),
  290. height: 138,
  291. width: 100,
  292. padding: EdgeInsets.all(5),
  293. decoration: BoxDecoration(
  294. boxShadow: [
  295. BoxShadow(
  296. color: MyColors.c7FE1E1E1,
  297. blurRadius: 5.0,
  298. ),
  299. ],
  300. color: Colors.white,
  301. borderRadius: BorderRadius.circular(4),
  302. ),
  303. child: Column(
  304. children: [
  305. MyViews().netImg('', 90, 90,
  306. placeholder: 'images/svg/goodsDefImg.svg'),
  307. Text(
  308. '8.9元充10元话费',
  309. style: TextStyle(color: MyColors.c333333, fontSize: 11),
  310. maxLines: 1,
  311. overflow: TextOverflow.ellipsis,
  312. softWrap: true,
  313. ),
  314. Row(
  315. children: [
  316. Text(
  317. '¥8.90',
  318. style: TextStyle(
  319. color: MyColors.cFF4233,
  320. fontSize: 13,
  321. fontWeight: FontWeight.bold),
  322. maxLines: 1,
  323. overflow: TextOverflow.ellipsis,
  324. softWrap: true,
  325. ),
  326. Container(
  327. decoration: BoxDecoration(
  328. border:
  329. Border.all(color: MyColors.cFF4233, width: 1),
  330. borderRadius: BorderRadius.circular(7),
  331. ),
  332. height: 14,
  333. width: 30,
  334. child: Text(
  335. '详情',
  336. style: TextStyle(
  337. color: MyColors.cFF4233, fontSize: 9),
  338. ),
  339. alignment: Alignment.center,
  340. )
  341. ],
  342. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  343. )
  344. ],
  345. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  346. crossAxisAlignment: CrossAxisAlignment.start,
  347. ),
  348. );
  349. },
  350. itemCount: 10,
  351. scrollDirection: Axis.horizontal,
  352. ),
  353. ),
  354. ],
  355. ),
  356. );
  357. }
  358. Widget carouselAndSearch(BuildContext context) {
  359. return SliverPersistentHeader(
  360. pinned: true,
  361. floating: false,
  362. delegate: _SliverAppBarDelegate(
  363. minHeight: minH,
  364. maxHeight: maxH,
  365. child: Stack(
  366. children: [
  367. Swiper(
  368. itemBuilder: (BuildContext context, int index) {
  369. return netImgs.length == 0
  370. ? GestureDetector(
  371. onTap: () {
  372. // EventBus().emit('showRP');
  373. },
  374. child: Image.asset(
  375. "${imgs[index]}",
  376. fit: BoxFit.cover,
  377. ),
  378. )
  379. : MyViews().netImg(imgURL(netImgs[index]), H,
  380. MediaQuery.of(context).size.width,
  381. placeholder: 'images/svg/goodsDefImg.svg');
  382. },
  383. itemCount: netImgs.length == 0 ? imgs.length : netImgs.length,
  384. viewportFraction: 1,
  385. scale: 1,
  386. autoplay: true,
  387. ),
  388. SafeArea(
  389. bottom: false,
  390. child: Stack(
  391. children: [
  392. Positioned(
  393. left: 0,
  394. child: Container(
  395. padding: EdgeInsets.only(left: 10, right: 10, top: 12),
  396. child: GestureDetector(
  397. onTap: () {
  398. addressSelection();
  399. },
  400. behavior: HitTestBehavior.translucent,
  401. child: Container(
  402. padding: EdgeInsets.only(left: 11, right: 14),
  403. decoration: BoxDecoration(
  404. boxShadow: [
  405. BoxShadow(
  406. color: MyColors.c7FE1E1E1,
  407. blurRadius: 5.0,
  408. ),
  409. ],
  410. color: Colors.white,
  411. borderRadius: BorderRadius.circular(20)),
  412. child: Row(
  413. children: [
  414. Icon(
  415. Icons.location_on_rounded,
  416. color: MyColors.c333333,
  417. size: 20,
  418. ),
  419. Text(
  420. province == null
  421. ? MyCookie().location != null
  422. ? MyCookie().location.city
  423. : '成都市'
  424. : city,
  425. style: TextStyle(
  426. color: MyColors.c333333,
  427. fontSize: 12,
  428. fontWeight: FontWeight.bold),
  429. ),
  430. ],
  431. ),
  432. height: 40,
  433. alignment: Alignment.center,
  434. ),
  435. ),
  436. alignment: Alignment.center,
  437. ),
  438. ),
  439. Positioned(
  440. top: 0,
  441. right: 50,
  442. child: Container(
  443. padding: EdgeInsets.only(left: 10, right: 10, top: 12),
  444. child: GestureDetector(
  445. onTap: () {
  446. showS = !showS;
  447. if (!showS) {
  448. _description.clear();
  449. }
  450. setState(() {});
  451. },
  452. behavior: HitTestBehavior.translucent,
  453. child: AnimatedContainer(
  454. height: 40,
  455. width: !showS
  456. ? 40
  457. : MediaQuery.of(context).size.width - 70,
  458. child: Row(
  459. children: [
  460. SvgPicture.asset(
  461. showS
  462. ? 'images/svg/箭头.svg'
  463. : 'images/svg/搜索.svg',
  464. height: 15,
  465. width: 15,
  466. color: MyColors.cFF4233,
  467. ),
  468. Visibility(
  469. visible: showS,
  470. child: Expanded(
  471. child: TextField(
  472. controller: _description,
  473. cursorColor: MyColors.cFF4233,
  474. cursorWidth: 1.0,
  475. onTap: () {},
  476. decoration: InputDecoration(
  477. border: InputBorder.none,
  478. disabledBorder: InputBorder.none,
  479. enabledBorder: InputBorder.none,
  480. focusedBorder: InputBorder.none,
  481. isDense: true,
  482. hintText: '请输入...',
  483. hintStyle: TextStyle(
  484. color: MyColors.c999999,
  485. fontSize: 16),
  486. contentPadding:
  487. const EdgeInsets.fromLTRB(
  488. 14, 4.5, 8, 4.5),
  489. ),
  490. maxLines: 1,
  491. style: TextStyle(
  492. color: MyColors.c333333,
  493. fontSize: 16,
  494. height: 1.3,
  495. letterSpacing: 0.2),
  496. keyboardType: TextInputType.text,
  497. onChanged: (t) {
  498. setState(() {});
  499. },
  500. ),
  501. ),
  502. ),
  503. Visibility(
  504. visible:
  505. showS && _description.text.isNotEmpty,
  506. child: GestureDetector(
  507. onTap: () {
  508. MyTools().hideKeyboard(context);
  509. _reController.requestRefresh();
  510. },
  511. behavior: HitTestBehavior.translucent,
  512. child: Container(
  513. child: MyViews()
  514. .myText('搜索', Colors.white, 13),
  515. decoration: BoxDecoration(
  516. color: MyColors.cFF4233,
  517. borderRadius: BorderRadius.circular(20),
  518. ),
  519. height: 40,
  520. width: 80,
  521. alignment: Alignment.center,
  522. ),
  523. ),
  524. )
  525. ],
  526. mainAxisAlignment: MainAxisAlignment.center,
  527. ),
  528. alignment: !showS
  529. ? Alignment.center
  530. : Alignment.centerLeft,
  531. padding: EdgeInsets.only(left: !showS ? 0 : 12),
  532. decoration: BoxDecoration(
  533. borderRadius:
  534. BorderRadius.all(Radius.circular(20)),
  535. color: Colors.white,
  536. ),
  537. duration: Duration(milliseconds: 200),
  538. ),
  539. ),
  540. alignment: Alignment.centerRight,
  541. ),
  542. ),
  543. Positioned(
  544. top: 0,
  545. right: 0,
  546. child: GestureDetector(
  547. onTap: () {
  548. MyTools().toPage(context, ScanPage(), (then) {
  549. if (then is String) {
  550. if (then.isNotEmpty && then != null) {
  551. Timer(Duration(milliseconds: 200), () {
  552. if (then.contains(
  553. 'https://bby.banghuo.net/pay.html?shop_uid=')) {
  554. } else {
  555. showToast('暂不支持该二维码');
  556. return;
  557. }
  558. MyTools().hideKeyboard(context);
  559. int shopUid = int.parse(then.split('=')[1]);
  560. print(shopUid);
  561. MyTools().toPage(context, NewPayToTheGangPage(shopUid,orderTypeOfflinePay), (then){});
  562. });
  563. }
  564. }
  565. });
  566. },
  567. behavior: HitTestBehavior.translucent,
  568. child: Container(
  569. margin: EdgeInsets.only(left: 10, right: 10, top: 12),
  570. height: 40,
  571. width: 40,
  572. child: SvgPicture.asset(
  573. 'images/svg/扫一扫_icon.svg',
  574. color: MyColors.cFF4233,
  575. height: 18,
  576. width: 18,
  577. ),
  578. alignment: Alignment.center,
  579. decoration: BoxDecoration(
  580. borderRadius: BorderRadius.circular(20),
  581. color: Colors.white),
  582. ),
  583. ),
  584. )
  585. ],
  586. ),
  587. ),
  588. ],
  589. )),
  590. );
  591. }
  592. @override
  593. // TODO: implement wantKeepAlive
  594. bool get wantKeepAlive => true;
  595. void getGoods(List<dynamic> shopUID) {
  596. var qData;
  597. if (shopUID.length == 0) {
  598. var conditions = ["public == true", "on_sale == true"];
  599. if (selectedIndex != 0) {
  600. conditions.add("category == ${tabs[selectedIndex]}");
  601. }
  602. if (_description.text.isNotEmpty) {
  603. conditions.add('title LIKE ${_description.text.toString()}');
  604. }
  605. qData = {
  606. "key": "commodity",
  607. "filters": {"conditions": conditions},
  608. "dims": commodityDims,
  609. "order_by": ["id,desc", "no,desc"],
  610. "paging": [page, 20]
  611. };
  612. } else {
  613. var conditions = ["shop_uid in $shopUID", "on_sale == true"];
  614. var conditions2 = ["public == true", "on_sale == true"];
  615. if (selectedIndex != 0) {
  616. conditions.add("category == ${tabs[selectedIndex]}");
  617. conditions2.add("category == ${tabs[selectedIndex]}");
  618. }
  619. if (_description.text.isNotEmpty) {
  620. conditions.add('title LIKE ${_description.text.toString()}');
  621. conditions2.add('title LIKE ${_description.text.toString()}');
  622. }
  623. qData = {
  624. "key": "commodity",
  625. "filters": {
  626. "or": true,
  627. "conditions": conditions,
  628. "filters": [
  629. {"conditions": conditions2}
  630. ]
  631. },
  632. "order_by": ["id,desc", "no,desc"],
  633. "dims": commodityDims,
  634. "paging": [page, 20]
  635. };
  636. }
  637. MyDio().query(qData, (response, hasError) {
  638. if (!hasError) {
  639. GoodsBeanEntity entity =
  640. GoodsBeanEntity().fromJson(json.decode(response.data.toString()));
  641. container.clear();
  642. container.addAll(entity.data.data);
  643. }
  644. queryAd();
  645. }, (error) {
  646. queryAd();
  647. });
  648. }
  649. void onRefresh() {
  650. page = 1;
  651. if (pageIndex == 1) {
  652. initTabs();
  653. findAStore();
  654. } else {
  655. storeType();
  656. checkPublicStores();
  657. }
  658. }
  659. void onLoading() {
  660. page++;
  661. if (pageIndex == 1) {
  662. findAStore();
  663. } else {
  664. checkPublicStores();
  665. }
  666. }
  667. Future<void> initTabs() async {
  668. List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
  669. MyDio().query({
  670. "key": "commodity_category",
  671. "filters": {},
  672. "dims": [
  673. "name",
  674. ]
  675. }, (response, hasError) {
  676. if (!hasError) {
  677. try {
  678. CommodityCategoryBeanEntity entity = CommodityCategoryBeanEntity()
  679. .fromJson(json.decode(response.data.toString()));
  680. commodityCategoryBeanData = entity.data;
  681. tabs.clear();
  682. tabs.add('全部');
  683. commodityCategoryBeanData.forEach((element) {
  684. tabs.insert(1, element.name);
  685. });
  686. if (selectedIndex > tabs.length - 1) {
  687. selectedIndex = 0;
  688. }
  689. setState(() {});
  690. } catch (e) {
  691. tabs.clear();
  692. tabs.add('全部');
  693. if (selectedIndex > tabs.length - 1) {
  694. selectedIndex = 0;
  695. }
  696. }
  697. } else {
  698. return commodityCategoryBeanData;
  699. }
  700. }, (error) {
  701. return commodityCategoryBeanData;
  702. });
  703. }
  704. findAStore() {
  705. MyDio().query({
  706. "key": "shop_user",
  707. "filters": {
  708. "or": true,
  709. "conditions": [
  710. "role!=$shopUserOwner",
  711. "user_uid==${MyCookie().getUID()}",
  712. "review_state==1"
  713. ],
  714. "filters": [
  715. {
  716. "conditions": [
  717. "role==$shopUserOwner",
  718. "user_uid==${MyCookie().getUID()}"
  719. ]
  720. }
  721. ]
  722. },
  723. "dims": shopUserDims,
  724. "paging": [1, 20000]
  725. }, (response, hasError) {
  726. if (!hasError) {
  727. MyShopBeanEntity entity =
  728. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  729. shops = entity.data.data;
  730. var shopUID = [];
  731. shops.forEach((element) {
  732. shopUID.add(element.shopUid);
  733. });
  734. getGoods(shopUID);
  735. }
  736. }, (error) {});
  737. }
  738. queryAd() {
  739. if (page == 1) {
  740. data.clear();
  741. puShop.clear();
  742. }
  743. if (pageIndex == 1) {
  744. data.addAll(container);
  745. } else {
  746. puShop.addAll(container);
  747. }
  748. setState(() {});
  749. endRe(_reController);
  750. return;
  751. // int count = 5;
  752. // MyDio().query({
  753. // "key": "ad",
  754. // "filters": {
  755. // "conditions": ['on_show == true']
  756. // },
  757. // "dims": adDims,
  758. // "order_by": ["id,desc", "no,desc"],
  759. // "paging": [page, count]
  760. // }, (response, hasError) {
  761. // if (!hasError) {
  762. // AdBeanEntity entity =
  763. // AdBeanEntity().fromJson(json.decode(response.data.toString()));
  764. // container.addAll(entity.data.data);
  765. // container.shuffle();
  766. // }
  767. // if (page == 1) {
  768. // data.clear();
  769. // puShop.clear();
  770. // }
  771. // if (pageIndex == 1) {
  772. // data.addAll(container);
  773. // } else {
  774. // puShop.addAll(container);
  775. // }
  776. // setState(() {});
  777. // endRe(_reController);
  778. // }, (error) {
  779. // if (page == 1) {
  780. // data.clear();
  781. // }
  782. // data.addAll(container);
  783. // setState(() {});
  784. // endRe(_reController);
  785. // });
  786. }
  787. void checkPublicStores() {
  788. var conditions = ['private==false', 'state == $shopStateNormal'];
  789. if (selectedIndex != 0) {
  790. conditions.add("category == ${tabs[selectedIndex]}");
  791. }
  792. if (_description.text.isNotEmpty) {
  793. conditions.add('name LIKE ${_description.text.toString()}');
  794. }
  795. if (MyCookie().location == null && province == null) {
  796. conditions.add('province == 四川省');
  797. conditions.add('city == 成都市');
  798. } else {
  799. if (province != null) {
  800. conditions.add('province == $province');
  801. conditions.add('city == $city');
  802. } else if (MyCookie().location != null) {
  803. conditions.add('province == ${MyCookie().location.province}');
  804. conditions.add('city == ${MyCookie().location.city}');
  805. }
  806. }
  807. MyDio().query({
  808. "key": "shop",
  809. "filters": {"conditions": conditions},
  810. "dims": shopDims,
  811. "order_by": ["id,desc", "no,desc"],
  812. "paging": [page, 20]
  813. }, (response, hasError) {
  814. if (!hasError) {
  815. StoreBeanEntity entity =
  816. StoreBeanEntity().fromJson(json.decode(response.data.toString()));
  817. container.clear();
  818. container.addAll(entity.data.data);
  819. }
  820. queryAd();
  821. }, (error) {
  822. queryAd();
  823. });
  824. }
  825. void storeType() {
  826. List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
  827. MyDio().query({
  828. "key": "shop_category",
  829. "filters": {},
  830. "dims": [
  831. "name",
  832. ]
  833. }, (response, hasError) {
  834. if (!hasError) {
  835. try {
  836. CommodityCategoryBeanEntity entity = CommodityCategoryBeanEntity()
  837. .fromJson(json.decode(response.data.toString()));
  838. commodityCategoryBeanData = entity.data;
  839. tabs.clear();
  840. tabs.add('全部');
  841. commodityCategoryBeanData.forEach((element) {
  842. tabs.insert(1, element.name);
  843. });
  844. setState(() {});
  845. } catch (e) {
  846. tabs.clear();
  847. tabs.add('全部');
  848. if (selectedIndex > tabs.length - 1) {
  849. selectedIndex = 0;
  850. }
  851. setState(() {});
  852. }
  853. }
  854. }, (error) {});
  855. }
  856. void addressSelection() {
  857. StateSetter ss;
  858. showModalBottomSheet(
  859. context: context,
  860. builder: (context) => BottomSheet(
  861. onClosing: () {},
  862. builder: (context) => Container(
  863. height: 350,
  864. child: Column(
  865. children: [
  866. StatefulBuilder(
  867. builder: (c, s) {
  868. ss = s;
  869. return Container(
  870. height: 40,
  871. color: Colors.white,
  872. padding: EdgeInsets.symmetric(horizontal: 15),
  873. child: Row(
  874. children: [
  875. Row(
  876. children: [
  877. Text(
  878. '定位到: ',
  879. style: TextStyle(
  880. color: MyColors.cFF4233, fontSize: 14),
  881. ),
  882. Text(
  883. _address == null
  884. ? '北京市 北京市'
  885. : '${_address.currentProvince.province} ${_address.currentCity.city}',
  886. style: TextStyle(
  887. color: MyColors.cFF4233, fontSize: 14),
  888. ),
  889. ],
  890. ),
  891. GestureDetector(
  892. child: Container(
  893. height: 40,
  894. width: 60,
  895. alignment: Alignment.center,
  896. child: Text(
  897. '确定',
  898. style: TextStyle(
  899. color: MyColors.cFF4233, fontSize: 16),
  900. ),
  901. ),
  902. onTap: () {
  903. if (_address == null) {
  904. province = '北京市';
  905. city = '北京市';
  906. setState(() {});
  907. _reController.requestRefresh();
  908. _address = null;
  909. Navigator.pop(context);
  910. } else {
  911. province = _address.currentProvince.province;
  912. city = _address.currentCity.city;
  913. setState(() {});
  914. _reController.requestRefresh();
  915. _address = null;
  916. Navigator.pop(context);
  917. }
  918. },
  919. behavior: HitTestBehavior.translucent,
  920. ),
  921. ],
  922. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  923. ),
  924. );
  925. },
  926. ),
  927. GestureDetector(
  928. onTap: () {
  929. if (MyCookie().location != null) {
  930. province = MyCookie().location.province;
  931. city = MyCookie().location.city;
  932. setState(() {});
  933. _reController.requestRefresh();
  934. _address = null;
  935. Navigator.pop(context);
  936. }
  937. },
  938. behavior: HitTestBehavior.translucent,
  939. child: Container(
  940. height: 60,
  941. color: Colors.white,
  942. padding: EdgeInsets.symmetric(horizontal: 20),
  943. child: Row(
  944. children: [
  945. Text(
  946. '当前定位:',
  947. style: TextStyle(color: MyColors.c333333, fontSize: 16),
  948. ),
  949. Text(
  950. MyCookie().location != null
  951. ? '${MyCookie().location.province} ${MyCookie().location.city}'
  952. : '请开启定位权限',
  953. style: TextStyle(color: MyColors.c333333, fontSize: 16),
  954. )
  955. ],
  956. ),
  957. ),
  958. ),
  959. Container(
  960. height: 250.0,
  961. child: AddressPicker(
  962. style: TextStyle(color: Colors.black, fontSize: 17),
  963. mode: AddressPickerMode.provinceAndCity,
  964. onSelectedAddressChanged: (address) {
  965. _address = address;
  966. ss(() {});
  967. },
  968. ),
  969. ),
  970. ],
  971. ),
  972. ),
  973. ),
  974. );
  975. }
  976. }
  977. class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
  978. _SliverAppBarDelegate({
  979. @required this.minHeight,
  980. @required this.maxHeight,
  981. @required this.child,
  982. });
  983. final double minHeight;
  984. final double maxHeight;
  985. final Widget child;
  986. @override
  987. double get minExtent => minHeight;
  988. @override
  989. double get maxExtent => max(maxHeight, minHeight);
  990. @override
  991. Widget build(
  992. BuildContext context, double shrinkOffset, bool overlapsContent) {
  993. return new SizedBox.expand(child: child);
  994. }
  995. @override
  996. bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {
  997. return maxHeight != oldDelegate.maxHeight ||
  998. minHeight != oldDelegate.minHeight ||
  999. child != oldDelegate.child;
  1000. }
  1001. }