From ebfec46349959e09ee78e8b6baed290595006289 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 10 May 2021 09:46:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=95=86=E5=9F=8E=E7=83=AD?= =?UTF-8?q?=E6=90=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants/api.dart | 3 +++ lib/ui/market/market_page.dart | 33 +++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 1ce73d18..041c75b9 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -261,6 +261,9 @@ class _Market { ///app商城中心:根据分类主键id查询商品信息列表 String get list => '/user/shop/findGoodsByCategoryId'; + + ///app商场中心:查询订阅量最高的4件商品(首页显示) + String get hotTop => '/user/shop/findTopGoods'; } class _Upload { diff --git a/lib/ui/market/market_page.dart b/lib/ui/market/market_page.dart index fbc2c1b1..1761b619 100644 --- a/lib/ui/market/market_page.dart +++ b/lib/ui/market/market_page.dart @@ -1,4 +1,9 @@ import 'package:aku_community/base/base_style.dart'; +import 'package:aku_community/constants/api.dart'; +import 'package:aku_community/models/market/goods_item.dart'; +import 'package:aku_community/ui/market/goods/goods_detail_page.dart'; +import 'package:aku_community/utils/network/base_model.dart'; +import 'package:aku_community/utils/network/net_util.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -26,17 +31,22 @@ class _MarketPageState extends State with AutomaticKeepAliveClientMixin, TickerProviderStateMixin { late TabController _tabController; List _marketModels = []; + List _hotItems = []; Future updateMarketInfo() async { - // List + _marketModels = await DisplayCategoryModel.top8; + BaseModel baseModel = await NetUtil().get(API.market.hotTop); + if (baseModel.status == true && baseModel.data != null) { + _hotItems = + (baseModel.data as List).map((e) => GoodsItem.fromJson(e)).toList(); + } } @override void initState() { super.initState(); _tabController = TabController(length: 2, vsync: this); - DisplayCategoryModel.top8.then((value) { - _marketModels = value; + updateMarketInfo().then((_) { setState(() {}); }); } @@ -86,6 +96,7 @@ class _MarketPageState extends State clipBehavior: Clip.antiAlias, borderRadius: BorderRadius.circular(8.w), child: GridView( + physics: NeverScrollableScrollPhysics(), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 4, childAspectRatio: 1, @@ -125,10 +136,12 @@ class _MarketPageState extends State fontSize: 20.sp, ), ), + 20.wb, ListView.separated( scrollDirection: Axis.horizontal, separatorBuilder: (_, __) => 20.wb, itemBuilder: (context, index) { + final item = _hotItems[index]; return MaterialButton( padding: EdgeInsets.symmetric(horizontal: 40.w), @@ -136,15 +149,23 @@ class _MarketPageState extends State shape: StadiumBorder( side: BorderSide( color: ktextSubColor, + width: 1, ), ), materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, - onPressed: () {}, - child: Text('123'), + onPressed: () { + Get.to(() => GoodsDetailPage(id: item.id)); + }, + child: Text( + item.title, + style: TextStyle( + color: ktextSubColor, + ), + ), ); }, - itemCount: 10, + itemCount: _hotItems.length, ).expand(), ], ),