home_page.dart 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'package:address_picker/address_picker.dart';
  4. import 'package:bbyyy/beans/ad_bean_entity.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/root_page/root_page_view.dart';
  21. import 'package:flutter/cupertino.dart';
  22. import 'package:flutter/material.dart';
  23. import 'package:flutter_svg/flutter_svg.dart';
  24. import 'package:flutter_swiper/flutter_swiper.dart';
  25. import 'package:pull_to_refresh/pull_to_refresh.dart';
  26. class HomePage extends StatefulWidget {
  27. @override
  28. _HomePageState createState() => _HomePageState();
  29. }
  30. class _HomePageState extends State<HomePage>
  31. with AutomaticKeepAliveClientMixin {
  32. var data = [];
  33. var container = [];
  34. var puShop = [];
  35. var imgs = ['images/banner1.png', 'images/banner2.png', 'images/banner3.png'];
  36. var netImgs = [];
  37. int selectedIndex = 0;
  38. var tabs = ['全部'];
  39. var types = ['货帮', '货品'];
  40. List<DropdownMenuItem<String>> sortItems = [];
  41. int typeIndex = 1;
  42. List<MyShopBeanDataData> shops = [];
  43. ScrollController _controller = ScrollController();
  44. double maxH;
  45. double minH = 164;
  46. double H = 0;
  47. bool showInput = false;
  48. TextEditingController _description = TextEditingController();
  49. FocusNode _descriptionFocus = FocusNode();
  50. RefreshController _reController = RefreshController(initialRefresh: true);
  51. int page = 1;
  52. int pageIndex = 0;
  53. bool showS = false;
  54. String province;
  55. String city;
  56. Address _address;
  57. @override
  58. void initState() {
  59. super.initState();
  60. EventBus().on('commodity_category', (arg) {
  61. setState(() {});
  62. });
  63. EventBus().on('uploadGoods', (arg) {
  64. _reController.requestRefresh();
  65. });
  66. EventBus().on('toTop', (arg) {
  67. _controller.animateTo(0.0,
  68. duration: Duration(milliseconds: 200), curve: Curves.easeIn);
  69. });
  70. EventBus().on('homeCarousel', (arg) {
  71. if (arg is HomeCarouselBeanEntity) {
  72. arg.data.forEach((element) {
  73. netImgs.add(element.path);
  74. });
  75. setState(() {});
  76. }
  77. });
  78. EventBus().on('商品变动', (arg) {
  79. _reController.requestRefresh();
  80. });
  81. EventBus().on('getLocation', (arg) {
  82. _reController.requestRefresh();
  83. setState(() {});
  84. });
  85. _controller.addListener(() {
  86. setState(() {
  87. if (_controller.offset == 0) {
  88. RootPageView().toTop = false;
  89. EventBus().emit('ChangePage');
  90. } else {
  91. RootPageView().toTop = true;
  92. EventBus().emit('ChangePage');
  93. }
  94. H = maxH - _controller.offset;
  95. if (H < minH) {
  96. H = minH;
  97. } else if (H > maxH) {
  98. H = maxH;
  99. }
  100. });
  101. });
  102. types.forEach((element) {
  103. sortItems.add(DropdownMenuItem(
  104. child: Text(
  105. element,
  106. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  107. ),
  108. value: element,
  109. ));
  110. });
  111. _descriptionFocus.addListener(() {
  112. if (_descriptionFocus.hasFocus) {
  113. } else {
  114. if (_description.text.isEmpty) {
  115. showInput = false;
  116. }
  117. }
  118. });
  119. homeCarousel();
  120. }
  121. @override
  122. void dispose() {
  123. // TODO: implement dispose
  124. super.dispose();
  125. EventBus().off('commodity_category');
  126. EventBus().off('uploadGoods');
  127. EventBus().off('toTop');
  128. EventBus().off('homeCarousel');
  129. EventBus().off('商品变动');
  130. EventBus().off('getLocation');
  131. }
  132. @override
  133. Widget build(BuildContext context) {
  134. maxH = MediaQuery.of(context).size.width * (520 / 750);
  135. minH = MediaQuery.of(context).padding.top + 64;
  136. if (H == 0) {
  137. H = maxH;
  138. }
  139. return GestureDetector(
  140. onTap: () {
  141. MyTools().hideKeyboard(context);
  142. },
  143. behavior: HitTestBehavior.translucent,
  144. child: Scaffold(
  145. resizeToAvoidBottomInset: false,
  146. body: Column(
  147. children: [
  148. Stack(
  149. children: [
  150. AnimatedContainer(
  151. height: H,
  152. duration: Duration(milliseconds: 200),
  153. child: Swiper(
  154. itemBuilder: (BuildContext context, int index) {
  155. return netImgs.length == 0
  156. ? Image.asset(
  157. "${imgs[index]}",
  158. fit: BoxFit.cover,
  159. )
  160. : MyViews().netImg(
  161. imgURL(netImgs[index]), H, double.infinity,
  162. placeholder: 'images/svg/goodsDefImg.svg');
  163. },
  164. itemCount:
  165. netImgs.length == 0 ? imgs.length : netImgs.length,
  166. viewportFraction: 1,
  167. scale: 1,
  168. autoplay: true,
  169. ),
  170. ),
  171. SafeArea(
  172. bottom: false,
  173. child: Stack(
  174. children: [
  175. // AnimatedOpacity(
  176. // duration: Duration(milliseconds: 200),
  177. // opacity: showS ? 0.0 : 1.0,
  178. // child: Container(
  179. // margin: EdgeInsets.only(top: 18),
  180. // width: double.infinity,
  181. // child: Row(
  182. // children: [
  183. // GestureDetector(
  184. // onTap: () {
  185. // setState(() {
  186. // pageIndex = 0;
  187. // _reController.requestRefresh();
  188. // });
  189. // },
  190. // behavior: HitTestBehavior.translucent,
  191. // child: Container(
  192. // height: 28,
  193. // width: 60,
  194. // alignment: Alignment.center,
  195. // child: Column(
  196. // children: [
  197. // Text(
  198. // '货帮',
  199. // style: TextStyle(
  200. // color: pageIndex == 0
  201. // ? MyColors.cFF4233
  202. // : MyColors.c333333,
  203. // fontSize: 16,
  204. // fontWeight: FontWeight.bold),
  205. // ),
  206. // Visibility(
  207. // child: Container(
  208. // width: 32,
  209. // height: 2,
  210. // decoration: BoxDecoration(
  211. // color: MyColors.cFF4233,
  212. // borderRadius:
  213. // BorderRadius.circular(1)),
  214. // ),
  215. // visible: pageIndex == 0,
  216. // ),
  217. // ],
  218. // ),
  219. // ),
  220. // ),
  221. // Container(
  222. // width: 40,
  223. // ),
  224. // GestureDetector(
  225. // onTap: () {
  226. // setState(() {
  227. // pageIndex = 1;
  228. // _reController.requestRefresh();
  229. // });
  230. // },
  231. // behavior: HitTestBehavior.translucent,
  232. // child: Container(
  233. // height: 28,
  234. // width: 60,
  235. // alignment: Alignment.center,
  236. // child: Column(
  237. // children: [
  238. // Text(
  239. // '商品',
  240. // style: TextStyle(
  241. // color: pageIndex == 1
  242. // ? MyColors.cFF4233
  243. // : MyColors.c333333,
  244. // fontSize: 16,
  245. // fontWeight: FontWeight.bold),
  246. // ),
  247. // Visibility(
  248. // child: Container(
  249. // width: 32,
  250. // height: 2,
  251. // decoration: BoxDecoration(
  252. // color: MyColors.cFF4233,
  253. // borderRadius:
  254. // BorderRadius.circular(1)),
  255. // ),
  256. // visible: pageIndex == 1,
  257. // ),
  258. // ],
  259. // ),
  260. // ),
  261. // ),
  262. // ],
  263. // mainAxisAlignment: MainAxisAlignment.center,
  264. // ),
  265. // ),
  266. // ),
  267. Positioned(
  268. left: 0,
  269. child: Container(
  270. padding:
  271. EdgeInsets.only(left: 10, right: 10, top: 12),
  272. child: GestureDetector(
  273. onTap: () {
  274. addressSelection();
  275. },
  276. behavior: HitTestBehavior.translucent,
  277. child: Container(
  278. padding: EdgeInsets.only(left: 11, right: 14),
  279. decoration: BoxDecoration(
  280. boxShadow: [
  281. BoxShadow(
  282. color: MyColors.c7FE1E1E1,
  283. blurRadius: 5.0,
  284. ),
  285. ],
  286. color: Colors.white,
  287. borderRadius: BorderRadius.circular(20)),
  288. child: Row(
  289. children: [
  290. Icon(
  291. Icons.location_on_rounded,
  292. color: MyColors.c333333,
  293. size: 20,
  294. ),
  295. Text(
  296. province == null
  297. ? MyCookie().location != null
  298. ? MyCookie().location.city
  299. : '成都市'
  300. : city,
  301. style: TextStyle(
  302. color: MyColors.c333333,
  303. fontSize: 12,
  304. fontWeight: FontWeight.bold),
  305. ),
  306. ],
  307. ),
  308. height: 40,
  309. alignment: Alignment.center,
  310. ),
  311. ),
  312. alignment: Alignment.center,
  313. ),
  314. ),
  315. Container(
  316. padding: EdgeInsets.only(left: 10, right: 10, top: 12),
  317. child: GestureDetector(
  318. onTap: () {
  319. showS = !showS;
  320. if (!showS) {
  321. _description.clear();
  322. }
  323. setState(() {});
  324. },
  325. behavior: HitTestBehavior.translucent,
  326. child: AnimatedContainer(
  327. height: 40,
  328. width:
  329. !showS ? 40 : MediaQuery.of(context).size.width,
  330. child: Row(
  331. children: [
  332. SvgPicture.asset(
  333. showS
  334. ? 'images/svg/箭头.svg'
  335. : 'images/svg/搜索.svg',
  336. height: 15,
  337. width: 15,
  338. color:
  339. showS ? MyColors.cFF4233 : Colors.white,
  340. ),
  341. Visibility(
  342. visible: showS,
  343. child: Expanded(
  344. child: TextField(
  345. controller: _description,
  346. cursorColor: MyColors.cFF4233,
  347. cursorWidth: 1.0,
  348. onTap: () {},
  349. decoration: InputDecoration(
  350. border: InputBorder.none,
  351. disabledBorder: InputBorder.none,
  352. enabledBorder: InputBorder.none,
  353. focusedBorder: InputBorder.none,
  354. isDense: true,
  355. hintText: '请输入...',
  356. hintStyle: TextStyle(
  357. color: MyColors.c999999,
  358. fontSize: 16),
  359. contentPadding:
  360. const EdgeInsets.fromLTRB(
  361. 14, 4.5, 8, 4.5),
  362. ),
  363. maxLines: 1,
  364. style: TextStyle(
  365. color: MyColors.c333333,
  366. fontSize: 16,
  367. height: 1.3,
  368. letterSpacing: 0.2),
  369. keyboardType: TextInputType.text,
  370. onChanged: (t) {
  371. setState(() {});
  372. },
  373. ),
  374. ),
  375. ),
  376. Visibility(
  377. visible:
  378. showS && _description.text.isNotEmpty,
  379. child: GestureDetector(
  380. onTap: () {
  381. MyTools().hideKeyboard(context);
  382. _reController.requestRefresh();
  383. },
  384. behavior: HitTestBehavior.translucent,
  385. child: Container(
  386. child: MyViews()
  387. .myText('搜索', Colors.white, 13),
  388. decoration: BoxDecoration(
  389. color: MyColors.cFF4233,
  390. borderRadius: BorderRadius.circular(20),
  391. ),
  392. height: 40,
  393. width: 80,
  394. alignment: Alignment.center,
  395. ),
  396. ),
  397. )
  398. ],
  399. mainAxisAlignment: MainAxisAlignment.center,
  400. ),
  401. alignment: !showS
  402. ? Alignment.center
  403. : Alignment.centerLeft,
  404. padding: EdgeInsets.only(left: !showS ? 0 : 12),
  405. decoration: BoxDecoration(
  406. borderRadius:
  407. BorderRadius.all(Radius.circular(20)),
  408. color: showS ? Colors.white : MyColors.cFF4233,
  409. border: Border.all(
  410. width: 0.5,
  411. color: showS
  412. ? MyColors.cf2f2f2
  413. : MyColors.cFF4233)),
  414. duration: Duration(milliseconds: 200),
  415. ),
  416. ),
  417. alignment: Alignment.centerRight,
  418. ),
  419. ],
  420. ),
  421. ),
  422. ],
  423. ),
  424. Container(
  425. height: 168,
  426. child: ListView.builder(
  427. padding: EdgeInsets.only(left: 12, right: 12),
  428. itemBuilder: (c, index) {
  429. return Container(margin:EdgeInsets.only(right: 10),height: 138,width: 100,color: Colors.amber,);
  430. },
  431. itemCount: 10,
  432. scrollDirection: Axis.horizontal,
  433. ),
  434. ),
  435. Column(
  436. children: [
  437. Container(
  438. height: 53,
  439. child: ListView.builder(
  440. padding: EdgeInsets.only(left: 12, right: 12),
  441. itemBuilder: (c, index) {
  442. return GestureDetector(
  443. onTap: () {
  444. setState(() {
  445. selectedIndex = index;
  446. _reController.requestRefresh();
  447. });
  448. },
  449. behavior: HitTestBehavior.translucent,
  450. child: Container(
  451. padding:
  452. EdgeInsets.only(right: 15, left: 15, bottom: 9),
  453. child: Column(
  454. children: [
  455. Text(
  456. tabs[index],
  457. style: TextStyle(
  458. color: index == selectedIndex
  459. ? MyColors.cFF4233
  460. : MyColors.c666666,
  461. fontSize: 14),
  462. ),
  463. Container(
  464. height: 10,
  465. child: Visibility(
  466. child: SvgPicture.asset('images/svg/tab.svg'),
  467. visible: index == selectedIndex,
  468. ),
  469. )
  470. ],
  471. mainAxisAlignment: MainAxisAlignment.end,
  472. ),
  473. height: 53,
  474. ),
  475. );
  476. },
  477. itemCount: tabs.length,
  478. scrollDirection: Axis.horizontal,
  479. ),
  480. ),
  481. Container(
  482. height: 1,
  483. color: MyColors.cf2f2f2,
  484. ),
  485. ],
  486. ),
  487. Expanded(
  488. flex: 1,
  489. child: SmartRefresher(
  490. controller: _reController,
  491. onRefresh: onRefresh,
  492. onLoading: onLoading,
  493. enablePullDown: true,
  494. enablePullUp: true,
  495. child: body(),
  496. ),
  497. )
  498. ],
  499. ),
  500. ),
  501. );
  502. }
  503. @override
  504. // TODO: implement wantKeepAlive
  505. bool get wantKeepAlive => true;
  506. void getGoods(List<dynamic> shopUID) {
  507. var qData;
  508. if (shopUID.length == 0) {
  509. var conditions = ["public == true", "on_sale == true"];
  510. if (selectedIndex != 0) {
  511. conditions.add("category == ${tabs[selectedIndex]}");
  512. }
  513. if (_description.text.isNotEmpty) {
  514. conditions.add('title LIKE ${_description.text.toString()}');
  515. }
  516. qData = {
  517. "key": "commodity",
  518. "filters": {"conditions": conditions},
  519. "dims": commodityDims,
  520. "order_by": ["id,desc", "no,desc"],
  521. "paging": [page, 20]
  522. };
  523. } else {
  524. var conditions = ["shop_uid in $shopUID", "on_sale == true"];
  525. var conditions2 = ["public == true", "on_sale == true"];
  526. if (selectedIndex != 0) {
  527. conditions.add("category == ${tabs[selectedIndex]}");
  528. conditions2.add("category == ${tabs[selectedIndex]}");
  529. }
  530. if (_description.text.isNotEmpty) {
  531. conditions.add('title LIKE ${_description.text.toString()}');
  532. conditions2.add('title LIKE ${_description.text.toString()}');
  533. }
  534. qData = {
  535. "key": "commodity",
  536. "filters": {
  537. "or": true,
  538. "conditions": conditions,
  539. "filters": [
  540. {"conditions": conditions2}
  541. ]
  542. },
  543. "order_by": ["id,desc", "no,desc"],
  544. "dims": commodityDims,
  545. "paging": [page, 20]
  546. };
  547. }
  548. MyDio().query(qData, (response, hasError) {
  549. if (!hasError) {
  550. GoodsBeanEntity entity =
  551. GoodsBeanEntity().fromJson(json.decode(response.data.toString()));
  552. container.clear();
  553. container.addAll(entity.data.data);
  554. }
  555. queryAd();
  556. }, (error) {
  557. queryAd();
  558. });
  559. }
  560. void onRefresh() {
  561. page = 1;
  562. if (pageIndex == 1) {
  563. initTabs();
  564. findAStore();
  565. } else {
  566. storeType();
  567. checkPublicStores();
  568. }
  569. }
  570. void onLoading() {
  571. page++;
  572. if (pageIndex == 1) {
  573. findAStore();
  574. } else {
  575. checkPublicStores();
  576. }
  577. }
  578. Future<void> initTabs() async {
  579. List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
  580. MyDio().query({
  581. "key": "commodity_category",
  582. "filters": {},
  583. "dims": [
  584. "name",
  585. ]
  586. }, (response, hasError) {
  587. if (!hasError) {
  588. try {
  589. CommodityCategoryBeanEntity entity = CommodityCategoryBeanEntity()
  590. .fromJson(json.decode(response.data.toString()));
  591. commodityCategoryBeanData = entity.data;
  592. tabs.clear();
  593. tabs.add('全部');
  594. commodityCategoryBeanData.forEach((element) {
  595. tabs.insert(1, element.name);
  596. });
  597. if (selectedIndex > tabs.length - 1) {
  598. selectedIndex = 0;
  599. }
  600. setState(() {});
  601. } catch (e) {
  602. tabs.clear();
  603. tabs.add('全部');
  604. if (selectedIndex > tabs.length - 1) {
  605. selectedIndex = 0;
  606. }
  607. }
  608. } else {
  609. return commodityCategoryBeanData;
  610. }
  611. }, (error) {
  612. return commodityCategoryBeanData;
  613. });
  614. }
  615. findAStore() {
  616. MyDio().query({
  617. "key": "shop_user",
  618. "filters": {
  619. "or": true,
  620. "conditions": [
  621. "role!=$shopUserOwner",
  622. "user_uid==${MyCookie().getUID()}",
  623. "review_state==1"
  624. ],
  625. "filters": [
  626. {
  627. "conditions": [
  628. "role==$shopUserOwner",
  629. "user_uid==${MyCookie().getUID()}"
  630. ]
  631. }
  632. ]
  633. },
  634. "dims": shopUserDims,
  635. "paging": [1, 20000]
  636. }, (response, hasError) {
  637. if (!hasError) {
  638. MyShopBeanEntity entity =
  639. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  640. shops = entity.data.data;
  641. var shopUID = [];
  642. shops.forEach((element) {
  643. shopUID.add(element.shopUid);
  644. });
  645. getGoods(shopUID);
  646. }
  647. }, (error) {});
  648. }
  649. queryAd() {
  650. int count = 5;
  651. MyDio().query({
  652. "key": "ad",
  653. "filters": {
  654. "conditions": ['on_show == true']
  655. },
  656. "dims": adDims,
  657. "order_by": ["id,desc", "no,desc"],
  658. "paging": [page, count]
  659. }, (response, hasError) {
  660. if (!hasError) {
  661. AdBeanEntity entity =
  662. AdBeanEntity().fromJson(json.decode(response.data.toString()));
  663. container.addAll(entity.data.data);
  664. container.shuffle();
  665. }
  666. if (page == 1) {
  667. data.clear();
  668. puShop.clear();
  669. }
  670. if (pageIndex == 1) {
  671. data.addAll(container);
  672. } else {
  673. puShop.addAll(container);
  674. }
  675. setState(() {});
  676. endRe(_reController);
  677. }, (error) {
  678. if (page == 1) {
  679. data.clear();
  680. }
  681. data.addAll(container);
  682. setState(() {});
  683. endRe(_reController);
  684. });
  685. }
  686. void checkPublicStores() {
  687. var conditions = ['private==false', 'state == $shopStateNormal'];
  688. if (selectedIndex != 0) {
  689. conditions.add("category == ${tabs[selectedIndex]}");
  690. }
  691. if (_description.text.isNotEmpty) {
  692. conditions.add('name LIKE ${_description.text.toString()}');
  693. }
  694. if (MyCookie().location == null && province == null) {
  695. conditions.add('province == 四川省');
  696. conditions.add('city == 成都市');
  697. } else {
  698. if (province != null) {
  699. conditions.add('province == $province');
  700. conditions.add('city == $city');
  701. } else if (MyCookie().location != null) {
  702. conditions.add('province == ${MyCookie().location.province}');
  703. conditions.add('city == ${MyCookie().location.city}');
  704. }
  705. }
  706. MyDio().query({
  707. "key": "shop",
  708. "filters": {"conditions": conditions},
  709. "dims": shopDims,
  710. "order_by": ["id,desc", "no,desc"],
  711. "paging": [page, 20]
  712. }, (response, hasError) {
  713. if (!hasError) {
  714. StoreBeanEntity entity =
  715. StoreBeanEntity().fromJson(json.decode(response.data.toString()));
  716. container.clear();
  717. container.addAll(entity.data.data);
  718. }
  719. queryAd();
  720. }, (error) {
  721. queryAd();
  722. });
  723. }
  724. void storeType() {
  725. List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
  726. MyDio().query({
  727. "key": "shop_category",
  728. "filters": {},
  729. "dims": [
  730. "name",
  731. ]
  732. }, (response, hasError) {
  733. if (!hasError) {
  734. try {
  735. CommodityCategoryBeanEntity entity = CommodityCategoryBeanEntity()
  736. .fromJson(json.decode(response.data.toString()));
  737. commodityCategoryBeanData = entity.data;
  738. tabs.clear();
  739. tabs.add('全部');
  740. commodityCategoryBeanData.forEach((element) {
  741. tabs.insert(1, element.name);
  742. });
  743. setState(() {});
  744. } catch (e) {
  745. tabs.clear();
  746. tabs.add('全部');
  747. if (selectedIndex > tabs.length - 1) {
  748. selectedIndex = 0;
  749. }
  750. setState(() {});
  751. }
  752. }
  753. }, (error) {});
  754. }
  755. body() {
  756. if (pageIndex == 1) {
  757. return body1();
  758. } else if (pageIndex == 0) {
  759. return body2();
  760. }
  761. }
  762. body1() {
  763. if (data.length == 0) {
  764. return SingleChildScrollView(child: noData());
  765. } else {
  766. return GridView.builder(
  767. controller: _controller,
  768. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  769. crossAxisCount: 2,
  770. childAspectRatio: 164 / 261,
  771. mainAxisSpacing: 8,
  772. crossAxisSpacing: 8),
  773. itemCount: data.length,
  774. padding: EdgeInsets.only(left: 14, right: 14, top: 14, bottom: 65),
  775. itemBuilder: (context, index) {
  776. return MyViews().getGoodsItem(data[index], context);
  777. });
  778. }
  779. }
  780. body2() {
  781. if (puShop.length == 0) {
  782. return SingleChildScrollView(child: noData());
  783. } else {
  784. return ListView.builder(
  785. controller: _controller,
  786. itemBuilder: (BuildContext context, int index) {
  787. return MyViews().pubShopItem(puShop[index], context);
  788. },
  789. itemCount: puShop.length,
  790. padding: EdgeInsets.all(10),
  791. );
  792. }
  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. }