update goods list view

hmxc
小赖 4 years ago
parent 9bf3a7dd8a
commit c6883718b4

@ -0,0 +1,31 @@
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:aku_community/model/common/img_model.dart';
part 'goods_item.g.dart';
@JsonSerializable()
class GoodsItem extends Equatable {
final int id;
final String title;
final String recommend;
final num sellingPrice;
final num markingPrice;
final int subscribeNum;
final List<ImgModel> imgList;
GoodsItem({
required this.id,
required this.title,
required this.recommend,
required this.sellingPrice,
required this.markingPrice,
required this.subscribeNum,
required this.imgList,
});
@override
List<Object?> get props => throw UnimplementedError();
factory GoodsItem.fromJson(Map<String, dynamic> json) =>
_$GoodsItemFromJson(json);
}

@ -0,0 +1,21 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'goods_item.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
GoodsItem _$GoodsItemFromJson(Map<String, dynamic> json) {
return GoodsItem(
id: json['id'] as int,
title: json['title'] as String,
recommend: json['recommend'] as String,
sellingPrice: json['sellingPrice'] as num,
markingPrice: json['markingPrice'] as num,
subscribeNum: json['subscribeNum'] as int,
imgList: (json['imgList'] as List<dynamic>)
.map((e) => ImgModel.fromJson(e as Map<String, dynamic>))
.toList(),
);
}

@ -1,100 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:waterfall_flow/waterfall_flow.dart';
import 'package:aku_community/ui/market/goods/goods_card.dart';
import 'package:aku_community/ui/market/goods/goods_list_view.dart';
import 'package:aku_community/utils/headers.dart';
@Deprecated('NO NEED THIS CLASS IN FUTURE')
class MarketData {
final String name;
final String path;
MarketData({
required this.name,
required this.path,
});
}
@Deprecated('NO NEED THIS LIST IN FUTURE')
List<MarketData> mockableMarketData = [
MarketData(name: '居家生活', path: R.ASSETS_ICONS_TOOL_JJSH_PNG),
MarketData(name: '数码家电', path: R.ASSETS_ICONS_TOOL_SMJD_PNG),
MarketData(name: '休闲副食', path: R.ASSETS_ICONS_TOOL_XXFS_PNG),
MarketData(name: '滋补保健', path: R.ASSETS_ICONS_TOOL_ZBBJ_PNG),
MarketData(name: '彩妆香水', path: R.ASSETS_ICONS_TOOL_CZXS_PNG),
MarketData(name: '服饰箱包', path: R.ASSETS_ICONS_TOOL_FSXB_PNG),
MarketData(name: '母婴玩具', path: R.ASSETS_ICONS_TOOL_MYWJ_PNG),
MarketData(name: '饮料酒水', path: R.ASSETS_ICONS_TOOL_YLJS_PNG),
];
@Deprecated('NO NEED THIS WIDGET IN FUTURE')
class MockableMarketWidget extends StatelessWidget {
final MarketData data;
const MockableMarketWidget({Key? key, required this.data}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialButton(
child: Column(
children: [
Spacer(),
Image.asset(
data.path,
height: 75.w,
width: 75.w,
),
12.hb,
Text(
data.name,
style: TextStyle(
fontSize: 24.sp,
color: Color(0xFF4A4B51),
),
),
Spacer(),
],
),
onPressed: () {
Get.to(
() => GoodsListView(),
);
},
);
}
}
@Deprecated('NO NEED THIS WIDGET IN FUTURE')
class MockableMarketList extends StatefulWidget {
MockableMarketList({Key? key}) : super(key: key);
@override
_MockableMarketListState createState() => _MockableMarketListState();
}
class _MockableMarketListState extends State<MockableMarketList> {
@override
Widget build(BuildContext context) {
return EasyRefresh(
header: MaterialHeader(completeDuration: Duration(milliseconds: 300)),
onRefresh: () async {},
child: WaterfallFlow(
padding: EdgeInsets.all(32.w),
gridDelegate: SliverWaterfallFlowDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 20.w,
crossAxisSpacing: 20.w,
),
children: [
GoodsCard(),
GoodsCard(),
GoodsCard(),
GoodsCard(),
GoodsCard(),
],
),
);
}
}

@ -35,7 +35,10 @@ class CategoryCard extends StatelessWidget {
),
onPressed: () {
Get.to(
() => GoodsListView(),
() => GoodsListView(
model: model,
subModels: [],
),
);
},
);

@ -103,7 +103,7 @@ class _CategoryPageState extends State<CategoryPage>
controller: _tabController,
physics: NeverScrollableScrollPhysics(),
children:
widget.models.map((e) => CategorySubView(id: e.id)).toList(),
widget.models.map((e) => CategorySubView(model: e)).toList(),
).expand(),
],
),

@ -7,8 +7,15 @@ import 'package:get/get.dart';
import 'package:aku_community/utils/headers.dart';
class CategorySubCard extends StatelessWidget {
final List<MarketCategoryModel> subModels;
final MarketCategoryModel selectModel;
final MarketCategoryModel model;
const CategorySubCard({Key? key, required this.model}) : super(key: key);
const CategorySubCard({
Key? key,
required this.model,
required this.subModels,
required this.selectModel,
}) : super(key: key);
@override
Widget build(BuildContext context) {
@ -17,14 +24,14 @@ class CategorySubCard extends StatelessWidget {
children: [
Spacer(),
FadeInImage.assetNetwork(
image: API.image(ImgModel.first(model.imgList)),
image: API.image(ImgModel.first(selectModel.imgList)),
placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
height: 75.w,
width: 75.w,
),
12.hb,
Text(
model.name,
selectModel.name,
style: TextStyle(
fontSize: 24.sp,
color: Color(0xFF4A4B51),
@ -33,9 +40,13 @@ class CategorySubCard extends StatelessWidget {
Spacer(),
],
),
onPressed: () {
Get.to(
() => GoodsListView(),
onPressed: () async {
await Get.to(
() => GoodsListView(
model: model,
subModels: subModels,
selectSubModel: selectModel,
),
);
},
);

@ -5,8 +5,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
class CategorySubView extends StatefulWidget {
final int id;
CategorySubView({Key? key, required this.id}) : super(key: key);
final MarketCategoryModel model;
CategorySubView({Key? key, required this.model}) : super(key: key);
@override
_CategorySubViewState createState() => _CategorySubViewState();
@ -20,7 +20,7 @@ class _CategorySubViewState extends State<CategorySubView> {
header: MaterialHeader(),
firstRefresh: true,
onRefresh: () async {
_models = await DisplayCategoryModel.fetchCategory(widget.id);
_models = await DisplayCategoryModel.fetchCategory(widget.model.id);
setState(() {});
},
child: GridView.builder(
@ -29,7 +29,11 @@ class _CategorySubViewState extends State<CategorySubView> {
),
itemBuilder: (context, index) {
final model = _models[index];
return CategorySubCard(model: model);
return CategorySubCard(
model: widget.model,
selectModel: model,
subModels: _models,
);
},
itemCount: _models.length,
),

@ -1,84 +1,137 @@
import 'package:aku_community/base/base_style.dart';
import 'package:aku_community/constants/api.dart';
import 'package:aku_community/model/common/img_model.dart';
import 'package:aku_community/models/market/market_category_model.dart';
import 'package:aku_community/ui/market/search/search_goods_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:waterfall_flow/waterfall_flow.dart';
import 'package:aku_community/ui/market/goods/goods_card.dart';
import 'package:aku_community/utils/headers.dart';
import 'package:aku_community/widget/bee_scaffold.dart';
class GoodsListView extends StatefulWidget {
GoodsListView({Key? key}) : super(key: key);
final MarketCategoryModel model;
final MarketCategoryModel? selectSubModel;
final List<MarketCategoryModel> subModels;
GoodsListView({
Key? key,
required this.model,
required this.subModels,
this.selectSubModel,
}) : super(key: key);
@override
_GoodsListViewState createState() => _GoodsListViewState();
}
class _GoodsListViewState extends State<GoodsListView> {
class _GoodsListViewState extends State<GoodsListView>
with TickerProviderStateMixin {
late MarketCategoryModel? _selectModel;
late TabController _tabController;
@override
void initState() {
super.initState();
int initIndex = 0;
//
if (widget.subModels.isNotEmpty) {
_selectModel = widget.subModels.first;
if (widget.selectSubModel != null) {
_selectModel = widget.selectSubModel;
initIndex = widget.subModels.indexOf(widget.selectSubModel!);
}
}
_tabController = TabController(
length: widget.subModels.length,
vsync: this,
initialIndex: initIndex,
);
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BeeScaffold(
title: 'TEST',
title: widget.model.name,
actions: [
IconButton(
icon: Icon(CupertinoIcons.search),
onPressed: () {},
onPressed: () {
Get.to(() => SearchGoodsPage());
},
)
],
appBarBottom: PreferredSize(
child: SizedBox(
height: 220.w,
child: ListView(
child: ListView.builder(
padding: EdgeInsets.symmetric(horizontal: 18.w),
scrollDirection: Axis.horizontal,
children: [
GoodsSubTypeButton(),
],
itemBuilder: (context, index) {
return GoodsSubTypeButton(
model: widget.subModels[index],
groupValue: _selectModel,
onTap: () {
_selectModel = widget.subModels[index];
_tabController.animateTo(index);
setState(() {});
},
);
},
itemCount: widget.subModels.length,
),
),
preferredSize: Size.fromHeight(220.w),
),
body: WaterfallFlow(
padding: EdgeInsets.all(32.w),
gridDelegate: SliverWaterfallFlowDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 20.w,
crossAxisSpacing: 20.w,
),
children: [
GoodsCard(),
GoodsCard(),
GoodsCard(),
GoodsCard(),
GoodsCard(),
],
body: TabBarView(
children: widget.subModels.map((e) => Text(e.name)).toList(),
controller: _tabController,
),
);
}
}
class GoodsSubTypeButton extends StatelessWidget {
const GoodsSubTypeButton({Key? key}) : super(key: key);
final MarketCategoryModel model;
final MarketCategoryModel? groupValue;
final VoidCallback onTap;
const GoodsSubTypeButton({
Key? key,
required this.model,
required this.groupValue,
required this.onTap,
}) : super(key: key);
bool get same => model == groupValue;
@override
Widget build(BuildContext context) {
return MaterialButton(
minWidth: 136.w,
padding: EdgeInsets.zero,
onPressed: () {},
onPressed: onTap,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
FadeInImage.assetNetwork(
image: API.image(ImgModel.first(model.imgList)),
placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
width: 100.w,
height: 100.w,
),
20.hb,
Text(
'健康运动',
model.name,
style: TextStyle(
fontSize: 24.sp,
color: same ? kPrimaryColor : ktextPrimary,
),
),
],

@ -8,7 +8,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:aku_community/ui/market/_market_data.dart';
import 'package:aku_community/ui/market/category/category_page.dart';
import 'package:aku_community/ui/market/search/search_goods_page.dart';
import 'package:aku_community/utils/headers.dart';
@ -131,8 +130,8 @@ class _MarketPageState extends State<MarketPage>
},
body: TabBarView(
children: [
MockableMarketList(),
MockableMarketList(),
SizedBox(),
SizedBox(),
],
controller: _tabController,
),

Loading…
Cancel
Save