parent
1977601ec8
commit
9bf3a7dd8a
@ -0,0 +1,33 @@
|
||||
import 'package:aku_community/constants/api.dart';
|
||||
import 'package:aku_community/models/market/market_category_model.dart';
|
||||
import 'package:aku_community/utils/network/base_model.dart';
|
||||
import 'package:aku_community/utils/network/net_util.dart';
|
||||
|
||||
class DisplayCategoryModel {
|
||||
final MarketCategoryModel model;
|
||||
final List<MarketCategoryModel> children;
|
||||
DisplayCategoryModel({
|
||||
required this.model,
|
||||
required this.children,
|
||||
});
|
||||
|
||||
static Future<List<MarketCategoryModel>> get top8 async {
|
||||
List<MarketCategoryModel> models = await fetchCategory(0);
|
||||
if (models.length >= 8)
|
||||
return models.getRange(0, 8).toList();
|
||||
else
|
||||
return models;
|
||||
}
|
||||
|
||||
///获取分类列表
|
||||
static Future<List<MarketCategoryModel>> fetchCategory(int parentId) async {
|
||||
BaseModel model = await NetUtil().get(
|
||||
API.market.category,
|
||||
params: {'parentId': parentId},
|
||||
);
|
||||
if (model.data == null) return [];
|
||||
return (model.data as List)
|
||||
.map((e) => MarketCategoryModel.fromJson(e))
|
||||
.toList();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
import 'package:aku_community/model/common/img_model.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'market_category_model.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class MarketCategoryModel extends Equatable {
|
||||
final int id;
|
||||
final String name;
|
||||
final List<ImgModel> imgList;
|
||||
MarketCategoryModel({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.imgList,
|
||||
});
|
||||
@override
|
||||
List<Object?> get props => [id];
|
||||
|
||||
factory MarketCategoryModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$MarketCategoryModelFromJson(json);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'market_category_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
MarketCategoryModel _$MarketCategoryModelFromJson(Map<String, dynamic> json) {
|
||||
return MarketCategoryModel(
|
||||
id: json['id'] as int,
|
||||
name: json['name'] as String,
|
||||
imgList: (json['imgList'] as List<dynamic>)
|
||||
.map((e) => ImgModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
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/goods/goods_list_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:aku_community/utils/headers.dart';
|
||||
|
||||
class CategoryCard extends StatelessWidget {
|
||||
final MarketCategoryModel model;
|
||||
const CategoryCard({Key? key, required this.model}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialButton(
|
||||
child: Column(
|
||||
children: [
|
||||
Spacer(),
|
||||
FadeInImage.assetNetwork(
|
||||
image: API.image(ImgModel.first(model.imgList)),
|
||||
placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
|
||||
height: 75.w,
|
||||
width: 75.w,
|
||||
),
|
||||
12.hb,
|
||||
Text(
|
||||
model.name,
|
||||
style: TextStyle(
|
||||
fontSize: 24.sp,
|
||||
color: Color(0xFF4A4B51),
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
Get.to(
|
||||
() => GoodsListView(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
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/goods/goods_list_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:aku_community/utils/headers.dart';
|
||||
|
||||
class CategorySubCard extends StatelessWidget {
|
||||
final MarketCategoryModel model;
|
||||
const CategorySubCard({Key? key, required this.model}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialButton(
|
||||
child: Column(
|
||||
children: [
|
||||
Spacer(),
|
||||
FadeInImage.assetNetwork(
|
||||
image: API.image(ImgModel.first(model.imgList)),
|
||||
placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
|
||||
height: 75.w,
|
||||
width: 75.w,
|
||||
),
|
||||
12.hb,
|
||||
Text(
|
||||
model.name,
|
||||
style: TextStyle(
|
||||
fontSize: 24.sp,
|
||||
color: Color(0xFF4A4B51),
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
Get.to(
|
||||
() => GoodsListView(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
import 'package:aku_community/models/market/display_category_model.dart';
|
||||
import 'package:aku_community/models/market/market_category_model.dart';
|
||||
import 'package:aku_community/ui/market/category/category_sub_card.dart';
|
||||
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);
|
||||
|
||||
@override
|
||||
_CategorySubViewState createState() => _CategorySubViewState();
|
||||
}
|
||||
|
||||
class _CategorySubViewState extends State<CategorySubView> {
|
||||
List<MarketCategoryModel> _models = [];
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return EasyRefresh(
|
||||
header: MaterialHeader(),
|
||||
firstRefresh: true,
|
||||
onRefresh: () async {
|
||||
_models = await DisplayCategoryModel.fetchCategory(widget.id);
|
||||
setState(() {});
|
||||
},
|
||||
child: GridView.builder(
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final model = _models[index];
|
||||
return CategorySubCard(model: model);
|
||||
},
|
||||
itemCount: _models.length,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue