import 'dart:convert' as convert;

import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/pages/invited_friends/models/invite_friend_data_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class InvitedFriendTemplate extends StatelessWidget {
  final InvitedFriendsPosterDataModel dataModel;
  final GlobalKey contentKey;

  Widget _qrcode;

  InvitedFriendTemplate(this.dataModel, {Key key, this.contentKey})
      : super(key: key) {
    _qrcode = Image.memory(convert.base64Decode(dataModel?.qrCode));
  }

  @override
  Widget build(BuildContext context) {
    return OverflowBox(
      maxHeight: double.infinity,
      maxWidth: 375, //固定宽度，保证所以手机下生成的模板一致
      child: RepaintBoundary(
        key: contentKey, // 用于导出模板样式的key
        child: Container(
          // 模板的内容
          width: 375,
          height: 667,
          child: Stack(
            children: <Widget>[
              Container(
                width: double.infinity,
                height: double.infinity,
                child: CachedNetworkImage(
                  imageUrl: dataModel?.posterImg ?? '',
                  fit: BoxFit.fill,
                ),
              ),
              Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: <Widget>[
                    Container(
                      width: 176,
                      height: 198,
                      // color: Colors.white,
                      decoration: BoxDecoration(
                          image: DecorationImage(
                              image: CachedNetworkImageProvider(
                                  dataModel?.whiteOutlineImg ?? ''))),
                      child: Column(
                        children: <Widget>[
                          Container(
                            margin: EdgeInsets.only(top: 4),
                            width: 24,
                            height: 24,
                            child: ClipRRect(
                              borderRadius: BorderRadius.circular(12),
                              child: CachedNetworkImage(
                                imageUrl: dataModel?.avatar ?? '',
                              ),
                            ),
                          ),
                          Container(
                            margin: EdgeInsets.only(top: 4),
                            width: 154,
                            height: 154,
                            child: _qrcode,
                          )
                        ],
                      ),
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Container(
                          width: 100,
                          height: 0.5,
                          color: Colors.white,
                        ),
                        Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: Text(
                            '邀请码',
                            style: TextStyle(fontSize: 18, color: Colors.white),
                          ),
                        ),
                        Container(
                          width: 100,
                          height: 0.5,
                          color: Colors.white,
                        ),
                      ],
                    ),
                    Container(
                      width: 176,
                      height: 40,
                      margin: EdgeInsets.only(top: 8, bottom: 40),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(13)),
                      child: Center(
                          child: Text(
                        dataModel.inviteCode,
                        style: TextStyle(
                            fontSize: 22, fontWeight: FontWeight.bold),
                      )),
                    )
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
