import 'package:flutter/material.dart';

class OrderItemWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 4, bottom: 4),
      padding: EdgeInsets.all(10),
      width: double.infinity,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(7.5), color: Colors.white),
      child: Column(
        children: <Widget>[
          _createHeader(),
          _createCenter(),
        ],
      ),
    );
  }

  Widget _createHeader() {
    return Padding(
      padding: const EdgeInsets.only(bottom: 8),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Text(
              '粉丝订单：Mickey',
              maxLines: 1,
              style: TextStyle(
                fontSize: 12,
                fontWeight: FontWeight.bold,
                color: Color(0xff333333),
              ),
            ),
          ),
          Text(
            '待结算',
            maxLines: 1,
            style: TextStyle(
              fontSize: 12,
              fontWeight: FontWeight.bold,
              color: Color(0xff999999),
            ),
          ),
        ],
      ),
    );
  }

  Widget _createCenter() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Container(
          margin: EdgeInsets.only(right: 10),
          width: 96,
          height: 96,
          color: Colors.black12,
        ),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              _createTitle(),
              _creteText('订单编号：15487945211587'),
              _creteText('下单时间：2020-06-18 17:11:15'),
              _creteText('完成时间：2020-06-18 17:11:15'),
            ],
          ),
        )
      ],
    );
  }

  Widget _createTitle() {
    List<InlineSpan> list = List();
    list.add(WidgetSpan(
      child: Container(
        padding: EdgeInsets.only(left: 2, right: 2, top: 3, bottom: 3),
        margin: EdgeInsets.only(right: 4),
        child: Text(
          '类型',
          style: TextStyle(
            fontSize: 9,
            height: 1,
            color: Colors.purpleAccent,
          ),
        ),
        decoration: BoxDecoration(
            color: Colors.amber, borderRadius: BorderRadius.circular(2.5)),
      ),
    ));
    list.add(
      TextSpan(
        text: '桶装水抽水器饮水机泵器动桶装水抽水器饮水机泵器动',
        style: TextStyle(
            fontSize: 15,
            color: Color(0xff333333),
            fontWeight: FontWeight.bold),
      ),
    );
    return RichText(
      maxLines: 1,
      overflow: TextOverflow.ellipsis,
      text: TextSpan(children: list),
    );
  }

  Widget _creteText(String text) {
    return Padding(
      padding: EdgeInsets.only(top: 4),
      child: Text(
        text,
        style: TextStyle(
          fontSize: 10,
          color: Color(0xff999999),
        ),
      ),
    );
  }
}
