import 'dart:convert' as convert;

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/widgets/goods_details/recommend/models/goods_detail_recommend_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class GoodsDetailsRecommendWidget extends StatefulWidget {
  final Map<String, dynamic> data;

  const GoodsDetailsRecommendWidget(this.data, {Key key}) : super(key: key);

  @override
  _GoodsDetailsRecommendWidgetState createState() =>
      _GoodsDetailsRecommendWidgetState();
}

class _GoodsDetailsRecommendWidgetState
    extends State<GoodsDetailsRecommendWidget> {
  GoodsDetailRecommendModel _style;

  @override
  void initState() {
    String d = widget.data['data'];
    Map<String, dynamic> json = convert.jsonDecode(d);
    _style = GoodsDetailRecommendModel.fromJson(json);

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        _createTitle(),
      ],
    );
  }

  Widget _createTitle() {
    return Container(
      width: double.infinity,
      height: 50,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          CachedNetworkImage(
            imageUrl: _style.recListIcon ?? '',
            width: 15,
            height: 15,
          ),
          Padding(
            padding: const EdgeInsets.only(left: 2.5),
            child: Text(
              _style.recListText,
              style: TextStyle(
                  color: HexColor.fromHex(_style?.recListTextColor ?? 'FF4242'),
                  fontSize: 14),
            ),
          )
        ],
      ),
    );
  }
}
