import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:link/view/add_link.dart'; import '../utils/size_fit.dart'; import '../utils/util.dart'; class HomeAddLink extends StatelessWidget { bool _disable = false; double scale; GlobalKey? _addLinkkey; var socialObj; HomeAddLink( {Key? key, required this.socialObj, GlobalKey? addLinkkey, required this.scale, bool? disable}) : super(key: key) { if (disable != null) { _disable = disable; } if (addLinkkey!=null){ _addLinkkey = addLinkkey; } } @override Widget build(BuildContext context) { SizeFit.initialize(context); String strColor = socialObj['background_color'].substring(1, 9); int value = int.parse(strColor, radix: 16); List shadows = []; double borderWidth = 0.0; String borderColor = '#00000000'; if (socialObj['border_width'] != null) { borderWidth = double.parse(socialObj['border_width']); borderColor = socialObj['border_color']; } if (socialObj['top_shadow'] != null) { String shadowColor = socialObj['top_shadow']['shadow_color'].substring(1, 9); int valueShadow = int.parse(shadowColor, radix: 16); shadows.add(BoxShadow( color: Color(valueShadow), blurRadius: double.parse(socialObj['top_shadow']['shadow_radius'])*scale, offset: Offset(double.parse(socialObj['top_shadow']['offset_x'])*scale, double.parse(socialObj['top_shadow']['offset_y'])*scale))); } if (socialObj['bottom_shadow'] != null) { String shadowColor = socialObj['bottom_shadow']['shadow_color'].substring(1, 9); int valueShadow = int.parse(shadowColor, radix: 16); shadows.add(BoxShadow( color: Color(valueShadow), blurRadius: double.parse(socialObj['bottom_shadow']['shadow_radius'])*scale, offset: Offset(double.parse(socialObj['bottom_shadow']['offset_x'])*scale, double.parse(socialObj['bottom_shadow']['offset_y'])*scale))); } Color linkColor = const Color(0xFF131314); if (socialObj['addlink_icon_color']!=null){ linkColor = Util().stringToColor(socialObj['addlink_icon_color']); } return Container( width: double.parse(socialObj['width']).px*scale + borderWidth.px * 2*scale, height: double.parse(socialObj['height']).px*scale + borderWidth.px * 2*scale, margin: EdgeInsets.only( bottom: double.parse((socialObj['space_height'])).px*scale), decoration: BoxDecoration( boxShadow: shadows, border: Border.all( color: Util().stringToColor(borderColor), width: borderWidth.px*scale), borderRadius: BorderRadius.circular( double.parse(socialObj['border_radius']).px*scale + borderWidth.px*scale)), child: Container( key: _disable == false ? _addLinkkey : null, width: double.parse(socialObj['width']).px*scale, height: double.parse(socialObj['height']).px*scale, padding: EdgeInsets.only( left: double.parse(socialObj['padding_horizontal']).px*scale, right: double.parse(socialObj['padding_horizontal']).px*scale), decoration: BoxDecoration( color: Color(value), // boxShadow: shadows, borderRadius: BorderRadius.all(Radius.circular( double.parse(socialObj['border_radius']).px*scale))), child: Row(children: [ SvgPicture.asset('assets/icons/link.svg', width: 24.px*scale, height: 24.px*scale, color: linkColor), SizedBox( width: 10.px*scale, ), Expanded( child: Text( '添加链接', style: TextStyle( color: Util().stringToColor(socialObj['text_color']), fontSize: double.parse(socialObj['font_size']).px*scale, fontWeight: socialObj['font_weight'] == 'bold' ? FontWeight.bold : FontWeight.normal), )), SvgPicture.asset( 'assets/icons/arrow_right.svg', width: 16.px*scale, height: 16.px*scale, color: Util().stringToColor(socialObj['arrow_color']), ) ]))); } }