import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/widgets/goods_details/upgrade_tip/model/upgrade_tip_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:cached_network_image/cached_network_image.dart';

///
/// 更新提示widget
///
class UpgradeTipWidget extends StatelessWidget {
  final Map<String, dynamic> model;
  UpgradeTipModel _upgradeTipModel;
  UpgradeTipWidget(this.model, {Key key}) : super(key: key){
    try{
      _upgradeTipModel = UpgradeTipModel.fromJson(jsonDecode(model['data']));
    }catch(e){
      Logger.log('UpgradeTipWidget e = $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.only(left: 12.5, right: 12.5, top: 12.5),
      decoration: BoxDecoration(
        color: Colors.white,
          borderRadius: BorderRadius.only(topLeft: Radius.circular(7.5), topRight: Radius.circular(7.5))
      ),
      child: Container(
        decoration: BoxDecoration(
          /// 背景颜色
          color: HexColor.fromHex(_upgradeTipModel?.bg_color ?? '#FFEFDA'),
          borderRadius: BorderRadius.circular(30),
        ),
        padding: const EdgeInsets.only(left: 10, right: 13, top: 10, bottom: 10),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            _geLeftWidget(_upgradeTipModel),
            _getRightWidget(_upgradeTipModel),
          ],
        ),
      ),
    );
  }

  /// 左边的视图
  Widget _geLeftWidget(UpgradeTipModel model) {
    return Row(
      children: <Widget>[
        /// 图标
        // Container(width: 15, height: 15, child: ,),
        CachedNetworkImage(imageUrl: model?.icon ?? '', width: 15,),

        const SizedBox(width: 7.5),

        /// 文字
        Text(model?.text ?? '下载APP升级运营商，享受更多收益', style: TextStyle(color: HexColor.fromHex( model?.text_color ?? '#C09023'), fontSize: 11))
      ],
    );
  }

  /// 右边的视图
  Widget _getRightWidget(UpgradeTipModel model) {
    return Text(model?.go_text ??'前往下载', style: TextStyle(color: HexColor.fromHex(model?.go_text_color ?? '#C09023'), fontSize: 11));
    // return Row(
    //   children: <Widget>[
    //     Text(model?.go_text ??'前往下载', style: TextStyle(color: HexColor.fromHex('#C09023'), fontSize: 11)),
    //     const SizedBox(width: 4),
    //     Text('》', style: TextStyle(color: HexColor.fromHex('#C09023'), fontSize: 11))
    //   ],
    // );
  }
}
