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(), ], ),