home_page.dart 35 KB

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