| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import 'package:flutter/material.dart';
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:twong/utils/index.dart';
- import 'package:twong/router/index.dart';
- import 'package:twong/models/index.dart';
- class ProductItem extends StatelessWidget {
- final Product data;
- final bool _isVip =
- Cache.user?.vip_level != null && Cache.user.vip_level > 0;
- ProductItem(this.data);
- @override
- Widget build(BuildContext context) {
- return GestureDetector(
- onTap: () {
- Navigator.pushNamed(context,
- RouteNames.productDetails, arguments: data.id);
- },
- child: Container(
- height: 118.px,
- padding: EdgeInsets.all(6.px),
- margin: EdgeInsets.only(top: 6.px, left: 8.px, right: 8.px),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.circular(6.px)
- ),
- child: Row(
- children: <Widget>[
- CachedNetworkImage(
- width: 118.px,
- height: 118.px,
- fit: BoxFit.scaleDown,
- imageUrl: data.image,
- imageBuilder: (BuildContext context,
- ImageProvider<dynamic> provider) {
- return Container(
- decoration: BoxDecoration(
- image: DecorationImage(
- image: provider,
- fit: BoxFit.cover
- ),
- ),
- );
- },
- placeholder: (BuildContext context, String str) {
- return Center(child: Utils.loadingWidget);
- },
- ),
- Expanded(child: Container(
- margin: EdgeInsets.only(left: 10.px, right: 10.px),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- height: 32.px,
- child: Text(data.store_name,
- style: TextStyle(
- fontWeight: FontWeight.bold, fontSize: 12.px)),
- ),
- Container(child: Row(
- children: [
- Icon(IconFonts.done_outline, color: Colors.grey, size: 12.px),
- Text(" 官方直营 信誉保障",
- style: TextStyle(color: Colors.grey, fontSize: 10.px)),
- ],
- )),
- Spacer(),
- Row(
- crossAxisAlignment: CrossAxisAlignment.end,
- children: [
- Expanded(child: _genPrice(data)),
- Text("最近销量: ${data.sales}", style:
- TextStyle(color: Colors.grey, fontSize: 10.px))
- ],)
- ],
- )),
- ),
- ],
- ),
- ),
- );
- }
- Widget _getVipPrice(dynamic price, { Color color, Widget leading }) {
- return Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Container(
- child: leading,
- margin: EdgeInsets.only(right: 4.px),
- ),
- RichText(
- text: TextSpan(
- text: I18n.$, style: TextStyle(color: color, fontSize: 10.px),
- children: [
- TextSpan(text: Utils.formatRMB(price),
- style: TextStyle(color: color, fontSize: 12.px),
- )
- ])
- ),
- ]);
- }
- Widget _genPrice(Product data) {
- if (_isVip) {
- return Container(
- margin: EdgeInsets.only(left: 6.px),
- child: Column(
- children: [
- _getVipPrice(data.vip_price, color: Colors.red, leading: Text("会:",
- style: TextStyle(fontSize: 12.px))),
- _getVipPrice(data.price, color: Colors.black87, leading: Text("购:",
- style: TextStyle(fontSize: 12.px))),
- _getVipPrice(num.parse(data.price) -
- (data.vip_price == null ? 0 : num.parse(data.vip_price)),
- color: Colors.green, leading: Text("赚:",
- style: TextStyle(fontSize: 12.px))),
- ],
- ),
- );
- }
- return Container(
- child: RichText(
- text: TextSpan(
- text: I18n.$,
- style: TextStyle(color: Colors.red, fontSize: 12.px),
- children: [
- TextSpan(text: data.price,
- style: TextStyle(color: Colors.red, fontSize: 16.px),
- children: [
- TextSpan(text: " ${I18n.$}",
- style: TextStyle(
- color: Colors.grey, fontSize: 12.px)
- ),
- TextSpan(text: Utils.formatRMB(data.price),
- style: TextStyle(
- color: Colors.grey, fontSize: 14.px,
- decoration: TextDecoration.lineThrough)
- )
- ])
- ])
- ));
- }
- }
|