
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

import 'package:twong/utils/index.dart';
import 'package:twong/models/cartInfo.dart';

class CartItem extends StatefulWidget {
  final CartInfo info;
  final Widget action;
  CartItem(this.info, {this.action});

  @override
  State<StatefulWidget> createState() {
    return _CartItemState();
  }
}

class _CartItemState extends State<CartItem> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 68.px,
      child: Row(
          children: [
            Container(width: 68.px, height: 68.px,
                margin: EdgeInsets.only(right: 12.px),
                child: CachedNetworkImage(
                    imageUrl: widget.info.productInfo["image"])),
            Expanded(child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    height: 38.px,
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(child: Container(
                          margin: EdgeInsets.only(right: 8.px),
                          child: Text(widget.info.productInfo["store_name"]),
                        )),
                        Text("x ${widget.info.cart_num}", style:
                        TextStyle(color: Colors.grey, fontSize: 16.px))
                      ],
                    ),
                  ),
                  Spacer(),
                  Row(children: [
                    Expanded(child: Text(
                        widget.info.productInfo["attrInfo"]["suk"],
                        style: TextStyle(color: Colors.grey))),
                    Text(Utils.formatRMB(widget.info.truePrice, show: true),
                        style: TextStyle(color: Colors.red)),
                    widget.action == null ? Container() : widget.action
                  ])
                ])),
          ]),
    );
  }
}