import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import '../bean/levitating_ball_pop_bean.dart'; ///悬浮球弹框 class NewBallDialog extends StatefulWidget { // 点击返回index 0 1 Function onTap; final LevitatingBallPopBean popoutBean; NewBallDialog({required this.onTap, required this.popoutBean}); @override _NewBallDialogState createState() => _NewBallDialogState(); } class _NewBallDialogState extends State { @override Widget build(BuildContext context) { final size = MediaQuery.of(context).size; final dw = size.width / 1.87178287318; final dh = size.width / 7.71373473323; double bl = 0, bt = 0, br = 0, bb = 0; if (widget.popoutBean.BgPicInfo != null) { if (widget.popoutBean.BgPicInfo!.PosY < 0) { bt = widget.popoutBean.BgPicInfo!.PosY * -1 + 0.0; } else { bb = widget.popoutBean.BgPicInfo!.PosY + 0.0; } if (widget.popoutBean.BgPicInfo!.PosX < 0) { bl = widget.popoutBean.BgPicInfo!.PosX * -1 + 0.0; } else { br = widget.popoutBean.BgPicInfo!.PosX + 0.0; } } double dl = 0, dt = 0, dr = 0, db = 0; if (widget.popoutBean.BtOKInfo != null) { if (widget.popoutBean.BtOKInfo!.PosY < 0) { dt = widget.popoutBean.BtOKInfo!.PosY * -1 + 0.0; } else { db = widget.popoutBean.BtOKInfo!.PosY + 0.0; } if (widget.popoutBean.BtOKInfo!.PosX < 0) { dl = widget.popoutBean.BtOKInfo!.PosX * -1 + 0.0; } else { dr = widget.popoutBean.BtOKInfo!.PosX + 0.0; } } double dl2 = 0, dt2 = 0, dr2 = 0, db2 = 0; if (widget.popoutBean.BtCloseInfo != null) { if (widget.popoutBean.BtCloseInfo!.PosY < 0) { dt2 = widget.popoutBean.BtCloseInfo!.PosY * -1 + 0.0; } else { db2 = widget.popoutBean.BtCloseInfo!.PosY + 0.0; } if (widget.popoutBean.BtCloseInfo!.PosX < 0) { dl2 = widget.popoutBean.BtCloseInfo!.PosX * -1 + 0.0; } else { dr2 = widget.popoutBean.BtCloseInfo!.PosX + 0.0; } } // String price = ""; // NetworkConfig.productIdList.forEach((key, value) { // if (widget.popoutBean.Text == key) { // price = value; // } // }); return Material( type: MaterialType.transparency, //透明类型 color: Color(0x1A000000), child: Center( // ClipRRect 创建圆角矩形 要不然发现下边button不是圆角 child: Container( child: Stack( alignment: Alignment.center, children: [ widget.popoutBean.BgPicInfo != null ? Container( margin: EdgeInsets.only(left: bl, top: bt, right: br, bottom: bb), child: CachedNetworkImage( width: widget.popoutBean.BgPicInfo!.W + 0.33, height: widget.popoutBean.BgPicInfo!.H + 0.33, fit: BoxFit.fill, imageUrl: widget.popoutBean.BgPicInfo != null && widget.popoutBean.BgPicInfo!.Pic != null ? widget.popoutBean.BgPicInfo!.Pic! : "", errorWidget: (context, url, error) => const Icon(Icons.error, size: 0), )) : Container(), widget.popoutBean.BtOKInfo != null ? Container( margin: EdgeInsets.only(left: dl, top: dt, right: dr, bottom: db), child: GestureDetector( onTap: () { Navigator.pop(context); if (widget.onTap != null) { widget.onTap(); } }, child: Stack( alignment: Alignment.center, children: [ CachedNetworkImage( width: widget.popoutBean.BtOKInfo!.W + 0.33, height: widget.popoutBean.BtOKInfo!.H + 0.33, fit: BoxFit.fill, imageUrl: widget.popoutBean.BtOKInfo != null && widget.popoutBean.BtOKInfo!.Pic != null ? widget.popoutBean.BtOKInfo!.Pic! : "", errorWidget: (context, url, error) => const Icon(Icons.error, size: 0), ), ], ), )) : Container(), widget.popoutBean.BtCloseInfo != null ? Container( margin: EdgeInsets.only(left: dl2, top: dt2, right: dr2, bottom: db2), child: GestureDetector( onTap: () { Navigator.pop(context); }, child: CachedNetworkImage( width: widget.popoutBean.BtCloseInfo!.W + 0.33, height: widget.popoutBean.BtCloseInfo!.H + 0.33, fit: BoxFit.fill, imageUrl: widget.popoutBean.BtCloseInfo != null && widget.popoutBean.BtCloseInfo!.Pic != null ? widget.popoutBean.BtCloseInfo!.Pic! : "", errorWidget: (context, url, error) => const Icon(Icons.error, size: 0), ))) : Container(), ], ), ), ), ); } }