home_page.dart 33 KB

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