基础组件库
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

253 rader
7.0 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. List<InlineSpan> list = List();
  69. if (shop != null && shop != '') {
  70. list.add(WidgetSpan(
  71. child: Container(
  72. padding: EdgeInsets.only(left: 2, right: 2, top: 3, bottom: 3),
  73. margin: EdgeInsets.only(right: 4),
  74. child: Text(
  75. shop,
  76. style: TextStyle(
  77. fontSize: 9,
  78. height: 1,
  79. color: HexColor.fromHex('#ffffff'),
  80. ),
  81. ),
  82. decoration: BoxDecoration(
  83. color: Colors.red, borderRadius: BorderRadius.circular(2.5)),
  84. ),
  85. ));
  86. }
  87. list.add(TextSpan(
  88. text: goods.goodTitle,
  89. style: TextStyle(
  90. fontSize: 15,
  91. color: HexColor.fromHex('#333333'),
  92. fontWeight: FontWeight.bold),
  93. ));
  94. return RichText(
  95. maxLines: 2,
  96. overflow: TextOverflow.ellipsis,
  97. text: TextSpan(children: list),
  98. );
  99. }
  100. Widget _createShop() {
  101. return Container(
  102. margin: EdgeInsets.only(top: 5),
  103. width: double.infinity,
  104. child: Row(
  105. children: <Widget>[
  106. Container(
  107. width: 15,
  108. height: 15,
  109. margin: EdgeInsets.only(right: 2),
  110. child: CachedNetworkImage(
  111. imageUrl: style.shopIcon,
  112. fit: BoxFit.fitHeight,
  113. ),
  114. ),
  115. Expanded(
  116. child: Text(
  117. goods.shopName,
  118. style: TextStyle(
  119. color: HexColor.fromHex(style.shopNameColor),
  120. fontSize: 11,
  121. fontWeight: FontWeight.w400),
  122. ))
  123. ],
  124. ),
  125. );
  126. }
  127. Widget _createCupone() {
  128. List<Widget> widgets = List();
  129. if (goods.coupon != null && goods.coupon != '') {
  130. widgets.add(Container(
  131. margin: EdgeInsets.only(right: 5),
  132. padding: EdgeInsets.only(left: 10, right: 10, top: 3, bottom: 3),
  133. decoration: BoxDecoration(
  134. color: HexColor.fromHex(style.couponBackgroundColor),
  135. borderRadius: BorderRadius.circular(2.5),
  136. ),
  137. child: Text(
  138. goods.coupon,
  139. textAlign: TextAlign.center,
  140. maxLines: 1,
  141. style: TextStyle(
  142. height: 1,
  143. fontSize: 11,
  144. color: HexColor.fromHex(style.couponFontColor),
  145. ),
  146. ),
  147. ));
  148. }
  149. if (goods.commission != null || goods.commission != '') {
  150. widgets.add(Container(
  151. margin: EdgeInsets.only(right: 5),
  152. padding: EdgeInsets.only(left: 10, right: 10, top: 3, bottom: 3),
  153. decoration: BoxDecoration(
  154. color: HexColor.fromHex(style.commissionBackgroundColor),
  155. borderRadius: BorderRadius.circular(2.5),
  156. ),
  157. child: Text(
  158. goods.commission,
  159. textAlign: TextAlign.center,
  160. maxLines: 1,
  161. style: TextStyle(
  162. height: 1,
  163. fontSize: 11,
  164. color: HexColor.fromHex(style.commissionFontColor),
  165. ),
  166. ),
  167. ));
  168. }
  169. return Container(
  170. margin: EdgeInsets.only(top: 6),
  171. child: Row(
  172. children: widgets,
  173. ),
  174. );
  175. }
  176. Widget _createBottom() {
  177. return Container(
  178. child: Row(
  179. crossAxisAlignment: CrossAxisAlignment.end,
  180. children: <Widget>[
  181. _createPrice(),
  182. _createOriginPrice(),
  183. Expanded(child: Container()),
  184. _createSale(),
  185. ],
  186. ),
  187. );
  188. }
  189. Widget _createPrice() {
  190. return RichText(
  191. maxLines: 1,
  192. overflow: TextOverflow.ellipsis,
  193. text: TextSpan(children: [
  194. TextSpan(
  195. text: '¥',
  196. style: TextStyle(
  197. fontSize: 10,
  198. color: HexColor.fromHex(style.currentPriceColor),
  199. fontWeight: FontWeight.bold,
  200. fontFamily: 'Din',
  201. package: 'zhiying_base_widget',
  202. ),
  203. ),
  204. TextSpan(
  205. text: goods.currentPrice,
  206. style: TextStyle(
  207. fontSize: 20,
  208. color: HexColor.fromHex(style.currentPriceColor),
  209. fontWeight: FontWeight.bold,
  210. fontFamily: 'Din',
  211. package: 'zhiying_base_widget',
  212. ),
  213. )
  214. ]),
  215. );
  216. }
  217. Widget _createOriginPrice() {
  218. return Padding(
  219. padding: EdgeInsets.only(bottom: 2),
  220. child: Text(
  221. '¥${goods.marketPrice}',
  222. style: TextStyle(
  223. fontSize: 11,
  224. height: 1,
  225. color: HexColor.fromHex(style.marketPriceColor),
  226. fontWeight: FontWeight.normal,
  227. fontFamily: 'Din',
  228. package: 'zhiying_base_widget',
  229. decoration: TextDecoration.lineThrough,
  230. ),
  231. ));
  232. }
  233. Widget _createSale() {
  234. return Text(
  235. '${goods.inorderCount}',
  236. style: TextStyle(fontSize: 11, color: HexColor.fromHex('#999999')),
  237. );
  238. }
  239. }