From 5049c99c50028402f8b83471e3b015a12cae4745 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Tue, 18 May 2021 19:08:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E7=94=B5=E5=AD=90?= =?UTF-8?q?=E5=95=86=E5=8A=A1=E8=AF=A6=E6=83=85=E9=A1=B5=20=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=EF=BC=9A=E8=8E=B7=E5=8F=96=E7=94=B5=E5=AD=90=E5=95=86?= =?UTF-8?q?=E5=8A=A1=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../electronic_commerc_card.dart | 71 +++++++++++++- .../electronic_commerc_detail_page.dart | 98 +++++++++++++++++++ .../electronic_commerc_page.dart | 31 +++--- .../electronic_commerc_view.dart | 58 +++++++++-- .../public_information_detail_page.dart | 4 +- 5 files changed, 236 insertions(+), 26 deletions(-) create mode 100644 lib/pages/electronic_commerc/electronic_commerc_detail_page.dart diff --git a/lib/pages/electronic_commerc/electronic_commerc_card.dart b/lib/pages/electronic_commerc/electronic_commerc_card.dart index 13ae1809..7b9a12ac 100644 --- a/lib/pages/electronic_commerc/electronic_commerc_card.dart +++ b/lib/pages/electronic_commerc/electronic_commerc_card.dart @@ -1,8 +1,20 @@ +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/pages/electronic_commerc/electronic_commerc_detail_page.dart'; +import 'package:flustars/flustars.dart'; import 'package:flutter/material.dart'; +import 'package:aku_community/models/electronic_commerc/electronic_commerc_list_model.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; +import 'package:velocity_x/velocity_x.dart'; +import 'package:aku_community/const/resource.dart'; + class ElectronicCommercCard extends StatefulWidget { - final int index; - ElectronicCommercCard({Key? key, required this.index}) : super(key: key); + final ElectronicCommercListModel model; + ElectronicCommercCard({Key? key, required this.model}) + : super(key: key); @override _ElectronicCommercCardState createState() => _ElectronicCommercCardState(); @@ -11,6 +23,59 @@ class ElectronicCommercCard extends StatefulWidget { class _ElectronicCommercCardState extends State { @override Widget build(BuildContext context) { - return Container(); + return _buildCard(widget.model); + } + + _buildCard(ElectronicCommercListModel model) { + return MaterialButton( + color: Colors.white, + elevation: 0, + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + onPressed: () { + Get.to(() => ElectronicCommercDetailPage(id: model.id)); + }, + padding: EdgeInsets.zero, + child: Container( + height: 248.w, + padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 24.w), + child: Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(model.title), + Spacer(), + DefaultTextStyle( + style: TextStyle( + color: ktextSubColor, + fontSize: 20.sp, + ), + child: Row( + children: [ + // Text('测试'), + Spacer(), + Text('发布于 ${DateUtil.formatDateStr( + model.createDate, + format: 'yyyy-MM-dd HH:mm', + )}'), + ], + ), + ), + ], + ), + ), + 32.w.widthBox, + FadeInImage.assetNetwork( + placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, + width: 240.w, + height: 200.w, + fit: BoxFit.cover, + image: API.image(ImgModel.first(model.imgList)), + ), + ], + ), + ), + ); } } diff --git a/lib/pages/electronic_commerc/electronic_commerc_detail_page.dart b/lib/pages/electronic_commerc/electronic_commerc_detail_page.dart new file mode 100644 index 00000000..060ab355 --- /dev/null +++ b/lib/pages/electronic_commerc/electronic_commerc_detail_page.dart @@ -0,0 +1,98 @@ +import 'package:aku_community/base/base_style.dart'; +import 'package:aku_community/constants/api.dart'; +import 'package:aku_community/utils/network/base_model.dart'; +import 'package:aku_community/utils/network/net_util.dart'; +import 'package:aku_community/widget/bee_scaffold.dart'; +import 'package:bot_toast/bot_toast.dart'; +import 'package:flustars/flustars.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:aku_community/models/electronic_commerc/electronic_commerc_detail_model.dart'; +import 'package:velocity_x/velocity_x.dart'; +class ElectronicCommercDetailPage extends StatefulWidget { + final int id; + ElectronicCommercDetailPage({Key? key, required this.id}) : super(key: key); + + @override + _ElectronicCommercDetailPageState createState() => _ElectronicCommercDetailPageState(); +} + +class _ElectronicCommercDetailPageState extends State { + + late EasyRefreshController _easyRefreshController; + bool _onload = true; + late ElectronicCommercDetailModel _detailModel; + @override + void initState() { + super.initState(); + _easyRefreshController = EasyRefreshController(); + } + + @override + void dispose() { + _easyRefreshController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return BeeScaffold( + title: _onload?'':_detailModel.electronicCommerceCategoryName, + bodyColor: Colors.white, + body: EasyRefresh( + firstRefresh: true, + header: MaterialHeader(), + onRefresh: () async { + BaseModel baseModel = await NetUtil() + .get(API.manager.electronicCommercDetail, params: { + "electronicCommerceId": widget.id, + }); + if (baseModel.status! && baseModel.data != null) { + _detailModel = ElectronicCommercDetailModel.fromJson(baseModel.data); + } else { + BotToast.showText(text: '无法获取信息'); + } + _onload = false; + setState(() {}); + }, + child: _onload + ? _emptyWidget() + : ListView( + padding: EdgeInsets.symmetric(vertical: 24.w, horizontal: 32.w), + children: [ + _detailModel.title.text + .size(32.sp) + .color(ktextPrimary) + .bold + .align(TextAlign.center) + .make(), + 24.w.heightBox, + SizedBox( + width: double.infinity, + child: _detailModel.content.text + .size(28.sp) + .color(ktextPrimary) + .make(), + ), + 40.w.heightBox, + Row( + children: [ + Spacer(), + '发布于 ${DateUtil.formatDateStr(_detailModel.createDate, format: 'MM-dd HH:mm')}' + .text + .size(24.sp) + .color(ktextSubColor) + .make(), + ], + ) + ], + ), + ), + ); + } + + Widget _emptyWidget() { + return Container(); + } + } diff --git a/lib/pages/electronic_commerc/electronic_commerc_page.dart b/lib/pages/electronic_commerc/electronic_commerc_page.dart index 61fdf445..89f2ad91 100644 --- a/lib/pages/electronic_commerc/electronic_commerc_page.dart +++ b/lib/pages/electronic_commerc/electronic_commerc_page.dart @@ -4,6 +4,7 @@ import 'package:aku_community/utils/network/base_model.dart'; import 'package:aku_community/utils/network/net_util.dart'; import 'package:aku_community/widget/bee_scaffold.dart'; import 'package:aku_community/widget/tab_bar/bee_tab_bar.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; import 'package:shimmer/shimmer.dart'; import 'package:velocity_x/velocity_x.dart'; @@ -32,12 +33,14 @@ class _ElectronicCommercPageState extends State Duration( milliseconds: 0, ), () async { + final cancel = BotToast.showLoading(); BaseModel baseModel = await NetUtil().get(API.manager.electronicCommercCategory); if (baseModel.status == true && baseModel.data != null) { _models = (baseModel.data as List) .map((e) => ElectronicCommercCategoryModel.fromJson(e)) .toList(); + cancel(); _tabs = List.generate(_models.length, (index) => _models[index].name); _onloading = false; _tabController = TabController(length: _tabs.length, vsync: this); @@ -70,7 +73,7 @@ class _ElectronicCommercPageState extends State children: [_buildShimmer()], ) : ElectronicCommercView( - index: index, + id: _models[index].id, ), ), ), @@ -103,18 +106,20 @@ class _ElectronicCommercPageState extends State ], ), ), - // Divider( - // height: 50.w, - // thickness: 1.w, - // color: Color(0xFFD8D8D8), - // ), - // GridView.count( - // crossAxisCount: 2, - // children: [ - // VxBox().height(53.w).width(53.w).color(Colors.white).make(), - - // ], - // ) + Divider( + height: 50.w, + thickness: 1.w, + color: Color(0xFFD8D8D8), + ), + GridView.count( + crossAxisCount: 2, + children: [ + VxBox().height(53.w).width(53.w).color(Colors.white).make(), + VxBox().height(53.w).width(53.w).color(Colors.white).make(), + VxBox().height(53.w).width(53.w).color(Colors.white).make(), + VxBox().height(53.w).width(53.w).color(Colors.white).make(), + ], + ) ], ), ); diff --git a/lib/pages/electronic_commerc/electronic_commerc_view.dart b/lib/pages/electronic_commerc/electronic_commerc_view.dart index accf7b57..c7d22489 100644 --- a/lib/pages/electronic_commerc/electronic_commerc_view.dart +++ b/lib/pages/electronic_commerc/electronic_commerc_view.dart @@ -1,23 +1,65 @@ +import 'package:aku_community/constants/api.dart'; import 'package:aku_community/pages/electronic_commerc/electronic_commerc_card.dart'; +import 'package:aku_community/pages/things_page/widget/bee_list_view.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:aku_community/models/electronic_commerc/electronic_commerc_list_model.dart'; +import 'package:velocity_x/velocity_x.dart'; class ElectronicCommercView extends StatefulWidget { - final int index; - ElectronicCommercView({Key? key, required this.index}) : super(key: key); + final int id; + ElectronicCommercView({Key? key, required this.id}) : super(key: key); @override _ElectronicCommercViewState createState() => _ElectronicCommercViewState(); } class _ElectronicCommercViewState extends State { + late EasyRefreshController _refreshController; + @override + void initState() { + super.initState(); + _refreshController = EasyRefreshController(); + } + + @override + void dispose() { + _refreshController.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { - return ListView( - padding: EdgeInsets.symmetric(vertical: 24.w,horizontal: 32.w), - children: [ - ElectronicCommercCard(index: widget.index), - ], - ); + // return ListView( + // padding: EdgeInsets.symmetric(vertical: 24.w,horizontal: 32.w), + // children: [ + // ElectronicCommercCard(index: widget.index), + // ], + // ); + return BeeListView( + path: API.manager.electronicCommercList, + controller: _refreshController, + extraParams: { + "electronicCommerceCategoryId":widget.id + }, + convert: (models) { + return models.tableList! + .map((e) => ElectronicCommercListModel.fromJson(e)) + .toList(); + }, + builder: (items) { + return ListView.separated( + padding: EdgeInsets.symmetric(vertical: 24.w), + itemBuilder: (context, index) { + return ElectronicCommercCard( + model: items[index], + ); + }, + separatorBuilder: (_, __) { + return 24.w.heightBox; + }, + itemCount: items.length); + }); } } diff --git a/lib/ui/home/public_infomation/public_information_detail_page.dart b/lib/ui/home/public_infomation/public_information_detail_page.dart index 56c3e2f7..cfc43523 100644 --- a/lib/ui/home/public_infomation/public_information_detail_page.dart +++ b/lib/ui/home/public_infomation/public_information_detail_page.dart @@ -40,7 +40,7 @@ class _PublicInformationDetailPageState @override Widget build(BuildContext context) { return BeeScaffold( - title: '公共资讯', + title: _onload ? '' : _detailModel.newsCategoryName, bodyColor: Colors.white, body: EasyRefresh( firstRefresh: true, @@ -64,7 +64,7 @@ class _PublicInformationDetailPageState padding: EdgeInsets.symmetric(vertical: 24.w, horizontal: 32.w), children: [ _detailModel.title.text - .size(36.sp) + .size(32.sp) .color(ktextPrimary) .bold .align(TextAlign.center)