From 549d7d9fcb2377625b77520e5bf8ee8f34d9b26d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=90=8C?= <494089941@qq.com> Date: Mon, 20 Jun 2022 11:39:27 +0800 Subject: [PATCH 1/2] delete duplicate code --- .../collection/collection_list_card.dart | 48 +------------- lib/ui/market/market_enums.dart | 12 ++++ lib/ui/market/market_home_goods_card.dart | 63 +++---------------- lib/ui/market/search/good_detail_page.dart | 49 +-------------- lib/ui/market/search/goods_list_card.dart | 48 +------------- lib/ui/market/search_goods_card.dart | 19 +++--- lib/ui/market/widget/goods_ tag_widget.dart | 60 ++++++++++++++++++ 7 files changed, 98 insertions(+), 201 deletions(-) create mode 100644 lib/ui/market/market_enums.dart create mode 100644 lib/ui/market/widget/goods_ tag_widget.dart diff --git a/lib/ui/market/collection/collection_list_card.dart b/lib/ui/market/collection/collection_list_card.dart index 350324b5..4a012a29 100644 --- a/lib/ui/market/collection/collection_list_card.dart +++ b/lib/ui/market/collection/collection_list_card.dart @@ -1,3 +1,4 @@ +import 'package:aku_new_community/ui/market/widget/goods_%20tag_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; @@ -67,8 +68,7 @@ class CollectionListCard extends StatelessWidget { ), ), 5.hb, - // _getIcon(2), - //_getIcon(model.kind??0), + GoodsTagWidget(type: model.kind??0), Spacer(), 20.hb, RichText( @@ -188,48 +188,4 @@ class CollectionListCard extends StatelessWidget { return count + '折'; } - Widget _getIcon(int type) { - if (type == 1) { - return Container( - width: 86.w, - height: 26.w, - alignment: Alignment.center, - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(4.w), - ), - gradient: LinearGradient( - begin: FractionalOffset.centerLeft, - end: FractionalOffset.centerRight, - colors: [Color(0xFFEC5329), Color(0xFFF58123)], - ), - ), - child: Text( - '京东自营', - style: TextStyle(fontSize: 18.sp, color: kForeGroundColor), - ), - ); - } else if (type == 2) { - return Container( - alignment: Alignment.center, - width: 86.w, - height: 30.w, - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(4.w), - ), - gradient: LinearGradient( - begin: FractionalOffset.centerLeft, - end: FractionalOffset.centerRight, - colors: [Color(0xFFF59B1C), Color(0xFFF5AF16)], - ), - ), - child: Text( - '京东POP', - style: TextStyle(fontSize: 18.sp, color: kForeGroundColor), - ), - ); - } else - return SizedBox(); - } } diff --git a/lib/ui/market/market_enums.dart b/lib/ui/market/market_enums.dart new file mode 100644 index 00000000..9ff91f8f --- /dev/null +++ b/lib/ui/market/market_enums.dart @@ -0,0 +1,12 @@ +enum GoodTag { + jdSelfSupport(1, '京东自营'), + jdPop(2, '京东POP'); + + final typeNum; + final typeStr; + + static GoodTag getValue(int value) => + GoodTag.values.firstWhere((element) => element.typeNum == value); + + const GoodTag(this.typeNum, this.typeStr); +} diff --git a/lib/ui/market/market_home_goods_card.dart b/lib/ui/market/market_home_goods_card.dart index 207e3b3d..d69913de 100644 --- a/lib/ui/market/market_home_goods_card.dart +++ b/lib/ui/market/market_home_goods_card.dart @@ -1,3 +1,4 @@ +import 'package:aku_new_community/ui/market/widget/goods_%20tag_widget.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -83,15 +84,15 @@ class MarketHomeGoodsCard extends StatelessWidget { style: TextStyle(fontSize: 28.sp, color: ktextPrimary), ), ), - // Padding( - // padding: EdgeInsets.only( - // left: 16.w, - // right: 16.w, - // top: 10.w, - // ), - // child: Container( - // child: _getIcon(1), - // )), + Padding( + padding: EdgeInsets.only( + left: 16.w, + right: 16.w, + top: 10.w, + ), + child: Container( + child: GoodsTagWidget(type: item.kind??0), + )), 10.hb, Padding( padding: EdgeInsets.symmetric( @@ -187,48 +188,4 @@ class MarketHomeGoodsCard extends StatelessWidget { return count + '折'; } - Widget _getIcon(int type) { - if (type == 1) { - return Container( - width: 86.w, - height: 26.w, - alignment: Alignment.center, - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(4.w), - ), - gradient: LinearGradient( - begin: FractionalOffset.centerLeft, - end: FractionalOffset.centerRight, - colors: [Color(0xFFEC5329), Color(0xFFF58123)], - ), - ), - child: Text( - '京东自营', - style: TextStyle(fontSize: 18.sp, color: kForeGroundColor), - ), - ); - } else if (type == 2) { - return Container( - alignment: Alignment.center, - width: 86.w, - height: 30.w, - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(4.w), - ), - gradient: LinearGradient( - begin: FractionalOffset.centerLeft, - end: FractionalOffset.centerRight, - colors: [Color(0xFFF59B1C), Color(0xFFF5AF16)], - ), - ), - child: Text( - '京东POP', - style: TextStyle(fontSize: 18.sp, color: kForeGroundColor), - ), - ); - } else - return SizedBox(); - } } diff --git a/lib/ui/market/search/good_detail_page.dart b/lib/ui/market/search/good_detail_page.dart index 536ee89f..68641705 100644 --- a/lib/ui/market/search/good_detail_page.dart +++ b/lib/ui/market/search/good_detail_page.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:aku_new_community/ui/market/widget/goods_%20tag_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -348,7 +349,7 @@ class _GoodDetailPageState extends State { overflow: TextOverflow.ellipsis, ), ), - // _getIcon(_goodDetail!.kind), + GoodsTagWidget(type: _goodDetail!.kind), Spacer(), Row( crossAxisAlignment: CrossAxisAlignment.center, @@ -558,52 +559,6 @@ class _GoodDetailPageState extends State { return url.substring(2); } - Widget _getIcon(int type) { - if (type == 1) { - return Container( - margin: EdgeInsets.only(left: 15.w), - width: 86.w, - height: 26.w, - alignment: Alignment.center, - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(4.w), - ), - gradient: LinearGradient( - begin: FractionalOffset.centerLeft, - end: FractionalOffset.centerRight, - colors: [Color(0xFFEC5329), Color(0xFFF58123)], - ), - ), - child: Text( - '京东自营', - style: TextStyle(fontSize: 18.sp, color: kForeGroundColor), - ), - ); - } else if (type == 2) { - return Container( - alignment: Alignment.center, - width: 86.w, - height: 30.w, - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(4.w), - ), - gradient: LinearGradient( - begin: FractionalOffset.centerLeft, - end: FractionalOffset.centerRight, - colors: [Color(0xFFF59B1C), Color(0xFFF5AF16)], - ), - ), - child: Text( - '京东POP', - style: TextStyle(fontSize: 18.sp, color: kForeGroundColor), - ), - ); - } else - return SizedBox(); - } - _bottomButton() { return Container( width: double.infinity, diff --git a/lib/ui/market/search/goods_list_card.dart b/lib/ui/market/search/goods_list_card.dart index 090865f2..55957a27 100644 --- a/lib/ui/market/search/goods_list_card.dart +++ b/lib/ui/market/search/goods_list_card.dart @@ -1,3 +1,4 @@ +import 'package:aku_new_community/ui/market/widget/goods_%20tag_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; @@ -76,8 +77,7 @@ class GoodsListCardState extends State { ), ), 5.hb, - // _getIcon(2), - //_getIcon(model.kind??0), + GoodsTagWidget(type: widget.model.kind??0), Spacer(), 20.hb, RichText( @@ -195,48 +195,4 @@ class GoodsListCardState extends State { return count + '折'; } - Widget _getIcon(int type) { - if (type == 1) { - return Container( - width: 86.w, - height: 26.w, - alignment: Alignment.center, - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(4.w), - ), - gradient: LinearGradient( - begin: FractionalOffset.centerLeft, - end: FractionalOffset.centerRight, - colors: [Color(0xFFEC5329), Color(0xFFF58123)], - ), - ), - child: Text( - '京东自营', - style: TextStyle(fontSize: 18.sp, color: kForeGroundColor), - ), - ); - } else if (type == 2) { - return Container( - alignment: Alignment.center, - width: 86.w, - height: 30.w, - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(4.w), - ), - gradient: LinearGradient( - begin: FractionalOffset.centerLeft, - end: FractionalOffset.centerRight, - colors: [Color(0xFFF59B1C), Color(0xFFF5AF16)], - ), - ), - child: Text( - '京东POP', - style: TextStyle(fontSize: 18.sp, color: kForeGroundColor), - ), - ); - } else - return SizedBox(); - } } diff --git a/lib/ui/market/search_goods_card.dart b/lib/ui/market/search_goods_card.dart index e84c5703..1fc6c0aa 100644 --- a/lib/ui/market/search_goods_card.dart +++ b/lib/ui/market/search_goods_card.dart @@ -1,3 +1,4 @@ +import 'package:aku_new_community/ui/market/widget/goods_%20tag_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; @@ -91,15 +92,15 @@ class _SearchGoodsCardState extends State { style: TextStyle(fontSize: 28.sp, color: ktextPrimary), ), ), - // Padding( - // padding: EdgeInsets.only( - // left: 16.w, - // right: 16.w, - // top: 10.w, - // ), - // child: Container( - // child: _getIcon(widget.item.kind ?? 0), - // )), + Padding( + padding: EdgeInsets.only( + left: 16.w, + right: 16.w, + top: 10.w, + ), + child: Container( + child: GoodsTagWidget(type: widget.item.kind ?? 0), + )), 10.hb, Padding( padding: EdgeInsets.symmetric( diff --git a/lib/ui/market/widget/goods_ tag_widget.dart b/lib/ui/market/widget/goods_ tag_widget.dart new file mode 100644 index 00000000..0a14d0a8 --- /dev/null +++ b/lib/ui/market/widget/goods_ tag_widget.dart @@ -0,0 +1,60 @@ +import 'package:aku_new_community/utils/headers.dart'; +import 'package:flutter/cupertino.dart'; + +import '../../../base/base_style.dart'; + +class GoodsTagWidget extends StatelessWidget { + final int type; + const GoodsTagWidget({Key? key, required this.type}) : super(key: key); + + @override + Widget build(BuildContext context) { + return _getIcon(type); + } + + Widget _getIcon(int type) { + if (type == 1) { + return Container( + width: 86.w, + height: 26.w, + alignment: Alignment.center, + decoration: BoxDecoration( + borderRadius: BorderRadius.all( + Radius.circular(4.w), + ), + gradient: LinearGradient( + begin: FractionalOffset.centerLeft, + end: FractionalOffset.centerRight, + colors: [Color(0xFFEC5329), Color(0xFFF58123)], + ), + ), + child: Text( + '京东自营', + style: TextStyle(fontSize: 18.sp, color: kForeGroundColor), + ), + ); + } else if (type == 2) { + return Container( + alignment: Alignment.center, + width: 86.w, + height: 30.w, + decoration: BoxDecoration( + borderRadius: BorderRadius.all( + Radius.circular(4.w), + ), + gradient: LinearGradient( + begin: FractionalOffset.centerLeft, + end: FractionalOffset.centerRight, + colors: [Color(0xFFF59B1C), Color(0xFFF5AF16)], + ), + ), + child: Text( + '京东POP', + style: TextStyle(fontSize: 18.sp, color: kForeGroundColor), + ), + ); + } else + return SizedBox(); + } + +} From f800ebb1f39ae7dcb32da3e4ac86e289fbc4a110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=90=8C?= <494089941@qq.com> Date: Mon, 20 Jun 2022 14:02:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=96=87=E5=AD=97?= =?UTF-8?q?=E6=B8=90=E5=8F=98=E5=AE=9E=E7=8E=B0=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/market/market_page.dart | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/ui/market/market_page.dart b/lib/ui/market/market_page.dart index d8e2d1c3..8c292179 100644 --- a/lib/ui/market/market_page.dart +++ b/lib/ui/market/market_page.dart @@ -512,18 +512,24 @@ class _MarketPageState extends State children: [ '积分商城'.richText.size(28.sp).italic.bold.black.make(), 8.wb, - Text( - '限时兑换', - style: TextStyle( - fontSize: 24.sp, - fontWeight: FontWeight.bold, - fontStyle: FontStyle.italic, - foreground: Paint() - ..shader = ui.Gradient.linear( - Offset(150, 690), Offset(150, 695), [ - Color(0xFFF94B4B), - Color(0xFFF7B86F), - ])), + ShaderMask( + shaderCallback: (bounds) { + return LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [ + Colors.red, + Colors.yellow, + ]).createShader(bounds); + }, + child: Text( + '限时兑换', + style: TextStyle( + fontSize: 24.sp, + color: Colors.white, + fontWeight: FontWeight.bold, + fontStyle: FontStyle.italic), + ), ), Spacer(), GestureDetector(