home_page.dart 34 KB

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