home_page.dart 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  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/map_demo/map_demo_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=='四川省'&&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().toPage(context, RecommendedTodayPage(), (then){});
  256. },
  257. behavior:HitTestBehavior.translucent,
  258. child: Row(
  259. children: [
  260. Text(
  261. '查看更多',
  262. style: TextStyle(color: MyColors.c666666, fontSize: 12),
  263. ),
  264. Icon(
  265. Icons.chevron_right,
  266. color: MyColors.c666666,
  267. )
  268. ],
  269. ),
  270. )
  271. ],
  272. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  273. ),
  274. ),
  275. Container(
  276. height: 1,
  277. color: MyColors.cf2f2f2,
  278. ),
  279. Container(
  280. height: 168,
  281. child: ListView.builder(
  282. padding: EdgeInsets.symmetric(horizontal: 16, vertical: 15),
  283. itemBuilder: (c, index) {
  284. return Container(
  285. margin: EdgeInsets.only(right: 10),
  286. height: 138,
  287. width: 100,
  288. padding: EdgeInsets.all(5),
  289. decoration: BoxDecoration(
  290. boxShadow: [
  291. BoxShadow(
  292. color: MyColors.c7FE1E1E1,
  293. blurRadius: 5.0,
  294. ),
  295. ],
  296. color: Colors.white,
  297. borderRadius: BorderRadius.circular(4),
  298. ),
  299. child: Column(
  300. children: [
  301. MyViews().netImg('', 90, 90,
  302. placeholder: 'images/svg/goodsDefImg.svg'),
  303. Text(
  304. '8.9元充10元话费',
  305. style: TextStyle(color: MyColors.c333333, fontSize: 11),
  306. maxLines: 1,
  307. overflow: TextOverflow.ellipsis,
  308. softWrap: true,
  309. ),
  310. Row(
  311. children: [
  312. Text(
  313. '¥8.90',
  314. style: TextStyle(
  315. color: MyColors.cFF4233,
  316. fontSize: 13,
  317. fontWeight: FontWeight.bold),
  318. maxLines: 1,
  319. overflow: TextOverflow.ellipsis,
  320. softWrap: true,
  321. ),
  322. Container(
  323. decoration: BoxDecoration(
  324. border:
  325. Border.all(color: MyColors.cFF4233, width: 1),
  326. borderRadius: BorderRadius.circular(7),
  327. ),
  328. height: 14,
  329. width: 30,
  330. child: Text('详情',style: TextStyle(color: MyColors.cFF4233,fontSize: 9),),
  331. alignment: Alignment.center,
  332. )
  333. ],mainAxisAlignment: MainAxisAlignment.spaceBetween,
  334. )
  335. ],mainAxisAlignment: MainAxisAlignment.spaceBetween,
  336. crossAxisAlignment: CrossAxisAlignment.start,
  337. ),
  338. );
  339. },
  340. itemCount: 10,
  341. scrollDirection: Axis.horizontal,
  342. ),
  343. ),
  344. ],
  345. ),
  346. );
  347. }
  348. Widget carouselAndSearch(BuildContext context) {
  349. return SliverPersistentHeader(
  350. pinned: true,
  351. floating: false,
  352. delegate: _SliverAppBarDelegate(
  353. minHeight: minH,
  354. maxHeight: maxH,
  355. child: Stack(
  356. children: [
  357. Swiper(
  358. itemBuilder: (BuildContext context, int index) {
  359. return netImgs.length == 0
  360. ? GestureDetector(
  361. onTap: (){
  362. MyTools().toPage(context, MapDemoPage(), (then){});
  363. },
  364. child: Image.asset(
  365. "${imgs[index]}",
  366. fit: BoxFit.cover,
  367. ),
  368. )
  369. : MyViews().netImg(
  370. imgURL(netImgs[index]), H, double.infinity,
  371. placeholder: 'images/svg/goodsDefImg.svg');
  372. },
  373. itemCount: netImgs.length == 0 ? imgs.length : netImgs.length,
  374. viewportFraction: 1,
  375. scale: 1,
  376. autoplay: true,
  377. ),
  378. SafeArea(
  379. bottom: false,
  380. child: Stack(
  381. children: [
  382. Positioned(
  383. left: 0,
  384. child: Container(
  385. padding: EdgeInsets.only(left: 10, right: 10, top: 12),
  386. child: GestureDetector(
  387. onTap: () {
  388. addressSelection();
  389. },
  390. behavior: HitTestBehavior.translucent,
  391. child: Container(
  392. padding: EdgeInsets.only(left: 11, right: 14),
  393. decoration: BoxDecoration(
  394. boxShadow: [
  395. BoxShadow(
  396. color: MyColors.c7FE1E1E1,
  397. blurRadius: 5.0,
  398. ),
  399. ],
  400. color: Colors.white,
  401. borderRadius: BorderRadius.circular(20)),
  402. child: Row(
  403. children: [
  404. Icon(
  405. Icons.location_on_rounded,
  406. color: MyColors.c333333,
  407. size: 20,
  408. ),
  409. Text(
  410. province == null
  411. ? MyCookie().location != null
  412. ? MyCookie().location.city
  413. : '成都市'
  414. : city,
  415. style: TextStyle(
  416. color: MyColors.c333333,
  417. fontSize: 12,
  418. fontWeight: FontWeight.bold),
  419. ),
  420. ],
  421. ),
  422. height: 40,
  423. alignment: Alignment.center,
  424. ),
  425. ),
  426. alignment: Alignment.center,
  427. ),
  428. ),
  429. Positioned(
  430. top: 0,
  431. right: 0,
  432. child: Container(
  433. padding: EdgeInsets.only(left: 10, right: 10, top: 12),
  434. child: GestureDetector(
  435. onTap: () {
  436. showS = !showS;
  437. if (!showS) {
  438. _description.clear();
  439. }
  440. setState(() {});
  441. },
  442. behavior: HitTestBehavior.translucent,
  443. child: AnimatedContainer(
  444. height: 40,
  445. width: !showS
  446. ? 40
  447. : MediaQuery.of(context).size.width - 20,
  448. child: Row(
  449. children: [
  450. SvgPicture.asset(
  451. showS
  452. ? 'images/svg/箭头.svg'
  453. : 'images/svg/搜索.svg',
  454. height: 15,
  455. width: 15,
  456. color:
  457. showS ? MyColors.cFF4233 : Colors.white,
  458. ),
  459. Visibility(
  460. visible: showS,
  461. child: Expanded(
  462. child: TextField(
  463. controller: _description,
  464. cursorColor: MyColors.cFF4233,
  465. cursorWidth: 1.0,
  466. onTap: () {},
  467. decoration: InputDecoration(
  468. border: InputBorder.none,
  469. disabledBorder: InputBorder.none,
  470. enabledBorder: InputBorder.none,
  471. focusedBorder: InputBorder.none,
  472. isDense: true,
  473. hintText: '请输入...',
  474. hintStyle: TextStyle(
  475. color: MyColors.c999999,
  476. fontSize: 16),
  477. contentPadding:
  478. const EdgeInsets.fromLTRB(
  479. 14, 4.5, 8, 4.5),
  480. ),
  481. maxLines: 1,
  482. style: TextStyle(
  483. color: MyColors.c333333,
  484. fontSize: 16,
  485. height: 1.3,
  486. letterSpacing: 0.2),
  487. keyboardType: TextInputType.text,
  488. onChanged: (t) {
  489. setState(() {});
  490. },
  491. ),
  492. ),
  493. ),
  494. Visibility(
  495. visible:
  496. showS && _description.text.isNotEmpty,
  497. child: GestureDetector(
  498. onTap: () {
  499. MyTools().hideKeyboard(context);
  500. _reController.requestRefresh();
  501. },
  502. behavior: HitTestBehavior.translucent,
  503. child: Container(
  504. child: MyViews()
  505. .myText('搜索', Colors.white, 13),
  506. decoration: BoxDecoration(
  507. color: MyColors.cFF4233,
  508. borderRadius: BorderRadius.circular(20),
  509. ),
  510. height: 40,
  511. width: 80,
  512. alignment: Alignment.center,
  513. ),
  514. ),
  515. )
  516. ],
  517. mainAxisAlignment: MainAxisAlignment.center,
  518. ),
  519. alignment: !showS
  520. ? Alignment.center
  521. : Alignment.centerLeft,
  522. padding: EdgeInsets.only(left: !showS ? 0 : 12),
  523. decoration: BoxDecoration(
  524. borderRadius:
  525. BorderRadius.all(Radius.circular(20)),
  526. color: showS ? Colors.white : MyColors.cFF4233,
  527. border: Border.all(
  528. width: 0.5,
  529. color: showS
  530. ? MyColors.cf2f2f2
  531. : MyColors.cFF4233)),
  532. duration: Duration(milliseconds: 200),
  533. ),
  534. ),
  535. alignment: Alignment.centerRight,
  536. ),
  537. ),
  538. ],
  539. ),
  540. ),
  541. ],
  542. )),
  543. );
  544. }
  545. @override
  546. // TODO: implement wantKeepAlive
  547. bool get wantKeepAlive => true;
  548. void getGoods(List<dynamic> shopUID) {
  549. var qData;
  550. if (shopUID.length == 0) {
  551. var conditions = ["public == true", "on_sale == true"];
  552. if (selectedIndex != 0) {
  553. conditions.add("category == ${tabs[selectedIndex]}");
  554. }
  555. if (_description.text.isNotEmpty) {
  556. conditions.add('title LIKE ${_description.text.toString()}');
  557. }
  558. qData = {
  559. "key": "commodity",
  560. "filters": {"conditions": conditions},
  561. "dims": commodityDims,
  562. "order_by": ["id,desc", "no,desc"],
  563. "paging": [page, 20]
  564. };
  565. } else {
  566. var conditions = ["shop_uid in $shopUID", "on_sale == true"];
  567. var conditions2 = ["public == true", "on_sale == true"];
  568. if (selectedIndex != 0) {
  569. conditions.add("category == ${tabs[selectedIndex]}");
  570. conditions2.add("category == ${tabs[selectedIndex]}");
  571. }
  572. if (_description.text.isNotEmpty) {
  573. conditions.add('title LIKE ${_description.text.toString()}');
  574. conditions2.add('title LIKE ${_description.text.toString()}');
  575. }
  576. qData = {
  577. "key": "commodity",
  578. "filters": {
  579. "or": true,
  580. "conditions": conditions,
  581. "filters": [
  582. {"conditions": conditions2}
  583. ]
  584. },
  585. "order_by": ["id,desc", "no,desc"],
  586. "dims": commodityDims,
  587. "paging": [page, 20]
  588. };
  589. }
  590. MyDio().query(qData, (response, hasError) {
  591. if (!hasError) {
  592. GoodsBeanEntity entity =
  593. GoodsBeanEntity().fromJson(json.decode(response.data.toString()));
  594. container.clear();
  595. container.addAll(entity.data.data);
  596. }
  597. queryAd();
  598. }, (error) {
  599. queryAd();
  600. });
  601. }
  602. void onRefresh() {
  603. page = 1;
  604. if (pageIndex == 1) {
  605. initTabs();
  606. findAStore();
  607. } else {
  608. storeType();
  609. checkPublicStores();
  610. }
  611. }
  612. void onLoading() {
  613. page++;
  614. if (pageIndex == 1) {
  615. findAStore();
  616. } else {
  617. checkPublicStores();
  618. }
  619. }
  620. Future<void> initTabs() async {
  621. List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
  622. MyDio().query({
  623. "key": "commodity_category",
  624. "filters": {},
  625. "dims": [
  626. "name",
  627. ]
  628. }, (response, hasError) {
  629. if (!hasError) {
  630. try {
  631. CommodityCategoryBeanEntity entity = CommodityCategoryBeanEntity()
  632. .fromJson(json.decode(response.data.toString()));
  633. commodityCategoryBeanData = entity.data;
  634. tabs.clear();
  635. tabs.add('全部');
  636. commodityCategoryBeanData.forEach((element) {
  637. tabs.insert(1, element.name);
  638. });
  639. if (selectedIndex > tabs.length - 1) {
  640. selectedIndex = 0;
  641. }
  642. setState(() {});
  643. } catch (e) {
  644. tabs.clear();
  645. tabs.add('全部');
  646. if (selectedIndex > tabs.length - 1) {
  647. selectedIndex = 0;
  648. }
  649. }
  650. } else {
  651. return commodityCategoryBeanData;
  652. }
  653. }, (error) {
  654. return commodityCategoryBeanData;
  655. });
  656. }
  657. findAStore() {
  658. MyDio().query({
  659. "key": "shop_user",
  660. "filters": {
  661. "or": true,
  662. "conditions": [
  663. "role!=$shopUserOwner",
  664. "user_uid==${MyCookie().getUID()}",
  665. "review_state==1"
  666. ],
  667. "filters": [
  668. {
  669. "conditions": [
  670. "role==$shopUserOwner",
  671. "user_uid==${MyCookie().getUID()}"
  672. ]
  673. }
  674. ]
  675. },
  676. "dims": shopUserDims,
  677. "paging": [1, 20000]
  678. }, (response, hasError) {
  679. if (!hasError) {
  680. MyShopBeanEntity entity =
  681. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  682. shops = entity.data.data;
  683. var shopUID = [];
  684. shops.forEach((element) {
  685. shopUID.add(element.shopUid);
  686. });
  687. getGoods(shopUID);
  688. }
  689. }, (error) {});
  690. }
  691. queryAd() {
  692. int count = 5;
  693. MyDio().query({
  694. "key": "ad",
  695. "filters": {
  696. "conditions": ['on_show == true']
  697. },
  698. "dims": adDims,
  699. "order_by": ["id,desc", "no,desc"],
  700. "paging": [page, count]
  701. }, (response, hasError) {
  702. if (!hasError) {
  703. AdBeanEntity entity =
  704. AdBeanEntity().fromJson(json.decode(response.data.toString()));
  705. container.addAll(entity.data.data);
  706. container.shuffle();
  707. }
  708. if (page == 1) {
  709. data.clear();
  710. puShop.clear();
  711. }
  712. if (pageIndex == 1) {
  713. data.addAll(container);
  714. } else {
  715. puShop.addAll(container);
  716. }
  717. setState(() {});
  718. endRe(_reController);
  719. }, (error) {
  720. if (page == 1) {
  721. data.clear();
  722. }
  723. data.addAll(container);
  724. setState(() {});
  725. endRe(_reController);
  726. });
  727. }
  728. void checkPublicStores() {
  729. var conditions = ['private==false', 'state == $shopStateNormal'];
  730. if (selectedIndex != 0) {
  731. conditions.add("category == ${tabs[selectedIndex]}");
  732. }
  733. if (_description.text.isNotEmpty) {
  734. conditions.add('name LIKE ${_description.text.toString()}');
  735. }
  736. if (MyCookie().location == null && province == null) {
  737. conditions.add('province == 四川省');
  738. conditions.add('city == 成都市');
  739. } else {
  740. if (province != null) {
  741. conditions.add('province == $province');
  742. conditions.add('city == $city');
  743. } else if (MyCookie().location != null) {
  744. conditions.add('province == ${MyCookie().location.province}');
  745. conditions.add('city == ${MyCookie().location.city}');
  746. }
  747. }
  748. MyDio().query({
  749. "key": "shop",
  750. "filters": {"conditions": conditions},
  751. "dims": shopDims,
  752. "order_by": ["id,desc", "no,desc"],
  753. "paging": [page, 20]
  754. }, (response, hasError) {
  755. if (!hasError) {
  756. StoreBeanEntity entity =
  757. StoreBeanEntity().fromJson(json.decode(response.data.toString()));
  758. container.clear();
  759. container.addAll(entity.data.data);
  760. }
  761. queryAd();
  762. }, (error) {
  763. queryAd();
  764. });
  765. }
  766. void storeType() {
  767. List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
  768. MyDio().query({
  769. "key": "shop_category",
  770. "filters": {},
  771. "dims": [
  772. "name",
  773. ]
  774. }, (response, hasError) {
  775. if (!hasError) {
  776. try {
  777. CommodityCategoryBeanEntity entity = CommodityCategoryBeanEntity()
  778. .fromJson(json.decode(response.data.toString()));
  779. commodityCategoryBeanData = entity.data;
  780. tabs.clear();
  781. tabs.add('全部');
  782. commodityCategoryBeanData.forEach((element) {
  783. tabs.insert(1, element.name);
  784. });
  785. setState(() {});
  786. } catch (e) {
  787. tabs.clear();
  788. tabs.add('全部');
  789. if (selectedIndex > tabs.length - 1) {
  790. selectedIndex = 0;
  791. }
  792. setState(() {});
  793. }
  794. }
  795. }, (error) {});
  796. }
  797. void addressSelection() {
  798. StateSetter ss;
  799. showModalBottomSheet(
  800. context: context,
  801. builder: (context) => BottomSheet(
  802. onClosing: () {},
  803. builder: (context) => Container(
  804. height: 350,
  805. child: Column(
  806. children: [
  807. StatefulBuilder(
  808. builder: (c, s) {
  809. ss = s;
  810. return Container(
  811. height: 40,
  812. color: Colors.white,
  813. padding: EdgeInsets.symmetric(horizontal: 15),
  814. child: Row(
  815. children: [
  816. Row(
  817. children: [
  818. Text(
  819. '定位到: ',
  820. style: TextStyle(
  821. color: MyColors.cFF4233, fontSize: 14),
  822. ),
  823. Text(
  824. _address == null
  825. ? '北京市 北京市'
  826. : '${_address.currentProvince.province} ${_address.currentCity.city}',
  827. style: TextStyle(
  828. color: MyColors.cFF4233, fontSize: 14),
  829. ),
  830. ],
  831. ),
  832. GestureDetector(
  833. child: Container(
  834. height: 40,
  835. width: 60,
  836. alignment: Alignment.center,
  837. child: Text(
  838. '确定',
  839. style: TextStyle(
  840. color: MyColors.cFF4233, fontSize: 16),
  841. ),
  842. ),
  843. onTap: () {
  844. if (_address == null) {
  845. province = '北京市';
  846. city = '北京市';
  847. setState(() {});
  848. _reController.requestRefresh();
  849. _address = null;
  850. Navigator.pop(context);
  851. } else {
  852. province = _address.currentProvince.province;
  853. city = _address.currentCity.city;
  854. setState(() {});
  855. _reController.requestRefresh();
  856. _address = null;
  857. Navigator.pop(context);
  858. }
  859. },
  860. behavior: HitTestBehavior.translucent,
  861. ),
  862. ],
  863. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  864. ),
  865. );
  866. },
  867. ),
  868. GestureDetector(
  869. onTap: () {
  870. if (MyCookie().location != null) {
  871. province = MyCookie().location.province;
  872. city = MyCookie().location.city;
  873. setState(() {});
  874. _reController.requestRefresh();
  875. _address = null;
  876. Navigator.pop(context);
  877. }
  878. },
  879. behavior: HitTestBehavior.translucent,
  880. child: Container(
  881. height: 60,
  882. color: Colors.white,
  883. padding: EdgeInsets.symmetric(horizontal: 20),
  884. child: Row(
  885. children: [
  886. Text(
  887. '当前定位:',
  888. style: TextStyle(color: MyColors.c333333, fontSize: 16),
  889. ),
  890. Text(
  891. MyCookie().location != null
  892. ? '${MyCookie().location.province} ${MyCookie().location.city}'
  893. : '请开启定位权限',
  894. style: TextStyle(color: MyColors.c333333, fontSize: 16),
  895. )
  896. ],
  897. ),
  898. ),
  899. ),
  900. Container(
  901. height: 250.0,
  902. child: AddressPicker(
  903. style: TextStyle(color: Colors.black, fontSize: 17),
  904. mode: AddressPickerMode.provinceAndCity,
  905. onSelectedAddressChanged: (address) {
  906. _address = address;
  907. ss(() {});
  908. },
  909. ),
  910. ),
  911. ],
  912. ),
  913. ),
  914. ),
  915. );
  916. }
  917. }
  918. class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
  919. _SliverAppBarDelegate({
  920. @required this.minHeight,
  921. @required this.maxHeight,
  922. @required this.child,
  923. });
  924. final double minHeight;
  925. final double maxHeight;
  926. final Widget child;
  927. @override
  928. double get minExtent => minHeight;
  929. @override
  930. double get maxExtent => max(maxHeight, minHeight);
  931. @override
  932. Widget build(
  933. BuildContext context, double shrinkOffset, bool overlapsContent) {
  934. return new SizedBox.expand(child: child);
  935. }
  936. @override
  937. bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {
  938. return maxHeight != oldDelegate.maxHeight ||
  939. minHeight != oldDelegate.minHeight ||
  940. child != oldDelegate.child;
  941. }
  942. }