home_page.dart 33 KB

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