基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

255 lines
7.1 KiB

  1. import 'dart:convert';
  2. import 'package:cached_network_image/cached_network_image.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:zhiying_base_widget/widgets/home_goods/models/home_goods_model.dart';
  5. import 'package:zhiying_base_widget/widgets/home_goods/models/home_goods_style_model.dart';
  6. import 'package:zhiying_comm/zhiying_comm.dart';
  7. // ignore: must_be_immutable
  8. class HomeGoodsItem extends StatelessWidget {
  9. final HomeGoodsModel goods;
  10. final HomeGoodsStyleModel style;
  11. final String shop;
  12. Map<String, dynamic> data;
  13. HomeGoodsItem(this.goods, this.style, {Key key, this.data, this.shop})
  14. : super(key: key) {
  15. if (this.data != null && this.data.containsKey('data')) {
  16. String data = this.data['data'];
  17. Map<String, dynamic> json = Map<String, dynamic>.from(jsonDecode(data));
  18. this.data = json;
  19. }
  20. }
  21. @override
  22. Widget build(BuildContext context) {
  23. return Container(
  24. margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 4, bottom: 4),
  25. padding: EdgeInsets.all(7.5),
  26. decoration: BoxDecoration(
  27. color: Colors.white,
  28. borderRadius: BorderRadius.all(Radius.circular(7.5))),
  29. child: Row(
  30. crossAxisAlignment: CrossAxisAlignment.start,
  31. children: <Widget>[
  32. Container(
  33. width: 126,
  34. height: 126,
  35. margin: EdgeInsets.only(right: 10),
  36. child: ClipRRect(
  37. borderRadius: BorderRadius.circular(7.5),
  38. child: CachedNetworkImage(
  39. imageUrl: goods.goodImage,
  40. fit: BoxFit.fitHeight,
  41. ),
  42. ),
  43. ),
  44. Expanded(
  45. child: Container(
  46. height: 126,
  47. width: double.infinity,
  48. child: Column(
  49. crossAxisAlignment: CrossAxisAlignment.start,
  50. children: <Widget>[
  51. Container(
  52. width: double.infinity,
  53. child: _createTitle(),
  54. ),
  55. _createShop(),
  56. _createCupone(),
  57. Expanded(child: Container()),
  58. _createBottom(),
  59. ],
  60. ),
  61. ),
  62. )
  63. ],
  64. ),
  65. );
  66. }
  67. Widget _createTitle() {
  68. return RichText(
  69. maxLines: 2,
  70. overflow: TextOverflow.ellipsis,
  71. text: TextSpan(children: [
  72. WidgetSpan(
  73. child: shop == null || shop == ''
  74. ? Container()
  75. : Container(
  76. padding:
  77. EdgeInsets.only(left: 2, right: 2, top: 3, bottom: 3),
  78. margin: EdgeInsets.only(right: 4),
  79. child: Text(
  80. shop,
  81. style: TextStyle(
  82. fontSize: 9,
  83. height: 1,
  84. color: HexColor.fromHex('#ffffff'),
  85. ),
  86. ),
  87. decoration: BoxDecoration(
  88. color: Colors.red,
  89. borderRadius: BorderRadius.circular(2.5)),
  90. ),
  91. ),
  92. TextSpan(
  93. text: goods.goodTitle,
  94. style: TextStyle(
  95. fontSize: 15,
  96. color: HexColor.fromHex('#333333'),
  97. fontWeight: FontWeight.bold),
  98. )
  99. ]),
  100. );
  101. }
  102. Widget _createShop() {
  103. return Container(
  104. margin: EdgeInsets.only(top: 5),
  105. width: double.infinity,
  106. child: Row(
  107. children: <Widget>[
  108. Container(
  109. width: 15,
  110. height: 15,
  111. margin: EdgeInsets.only(right: 2),
  112. child: CachedNetworkImage(
  113. imageUrl: style.shopIcon,
  114. fit: BoxFit.fitHeight,
  115. ),
  116. ),
  117. Expanded(
  118. child: Text(
  119. goods.shopName,
  120. style: TextStyle(
  121. color: HexColor.fromHex(style.shopNameColor),
  122. fontSize: 11,
  123. fontWeight: FontWeight.w400),
  124. ))
  125. ],
  126. ),
  127. );
  128. }
  129. Widget _createCupone() {
  130. List<Widget> widgets = List();
  131. if (goods.coupon != null && goods.coupon != '') {
  132. widgets.add(Container(
  133. margin: EdgeInsets.only(right: 5),
  134. padding: EdgeInsets.only(left: 10, right: 10, top: 2, bottom: 2),
  135. decoration: BoxDecoration(
  136. color: HexColor.fromHex(style.couponBackgroundColor),
  137. borderRadius: BorderRadius.circular(2.5),
  138. ),
  139. child: Text(
  140. goods.coupon,
  141. textAlign: TextAlign.center,
  142. maxLines: 1,
  143. style: TextStyle(
  144. height: 1,
  145. fontSize: 11,
  146. color: HexColor.fromHex(style.couponFontColor),
  147. ),
  148. ),
  149. ));
  150. }
  151. if (goods.commission != null || goods.commission != '') {
  152. widgets.add(Container(
  153. margin: EdgeInsets.only(right: 5),
  154. padding: EdgeInsets.only(left: 10, right: 10, top: 2, bottom: 2),
  155. decoration: BoxDecoration(
  156. color: HexColor.fromHex(style.commissionBackgroundColor),
  157. borderRadius: BorderRadius.circular(2.5),
  158. ),
  159. child: Text(
  160. goods.commission,
  161. textAlign: TextAlign.center,
  162. maxLines: 1,
  163. style: TextStyle(
  164. height: 1,
  165. fontSize: 11,
  166. color: HexColor.fromHex(style.commissionFontColor),
  167. ),
  168. ),
  169. ));
  170. }
  171. return Container(
  172. margin: EdgeInsets.only(top: 6),
  173. child: Row(
  174. children: widgets,
  175. ),
  176. );
  177. }
  178. Widget _createBottom() {
  179. return Container(
  180. child: Row(
  181. crossAxisAlignment: CrossAxisAlignment.end,
  182. children: <Widget>[
  183. _createPrice(),
  184. _createOriginPrice(),
  185. Expanded(child: Container()),
  186. _createSale(),
  187. ],
  188. ),
  189. );
  190. }
  191. Widget _createPrice() {
  192. return RichText(
  193. maxLines: 1,
  194. overflow: TextOverflow.ellipsis,
  195. text: TextSpan(children: [
  196. TextSpan(
  197. text: '¥',
  198. style: TextStyle(
  199. fontSize: 10,
  200. color: HexColor.fromHex(style.currentPriceColor),
  201. fontWeight: FontWeight.bold,
  202. fontFamily: 'Din',
  203. package: 'zhiying_base_widget',
  204. ),
  205. ),
  206. TextSpan(
  207. text: goods.currentPrice,
  208. style: TextStyle(
  209. fontSize: 20,
  210. color: HexColor.fromHex(style.currentPriceColor),
  211. fontWeight: FontWeight.bold,
  212. fontFamily: 'Din',
  213. package: 'zhiying_base_widget',
  214. ),
  215. )
  216. ]),
  217. );
  218. }
  219. Widget _createOriginPrice() {
  220. return Padding(
  221. padding: EdgeInsets.only(bottom: 2),
  222. child: Text(
  223. '¥${goods.marketPrice}',
  224. style: TextStyle(
  225. fontSize: 11,
  226. height: 1,
  227. color: HexColor.fromHex(style.marketPriceColor),
  228. fontWeight: FontWeight.normal,
  229. fontFamily: 'Din',
  230. package: 'zhiying_base_widget',
  231. decoration: TextDecoration.lineThrough,
  232. ),
  233. ));
  234. }
  235. Widget _createSale() {
  236. return Text(
  237. '${goods.inorderCount}',
  238. style: TextStyle(fontSize: 11, color: HexColor.fromHex('#999999')),
  239. );
  240. }
  241. }