import 'package:chat/generated/i18n.dart'; import 'package:chat/r.dart'; import 'package:chat/utils/image_frame_animation.dart'; import 'package:chat/utils/screen.dart'; import 'package:flutter/material.dart'; class AnimEffect { static showEffect(BuildContext context, int giftId) { var overlayState = Overlay.of(context); OverlayEntry overlayEntry = OverlayEntry(builder: (context) { return LayoutBuilder(builder: (context, constraints) { var item; if (giftId == 2) { var imgList = [ R.assetsImagesGiftShow21, R.assetsImagesGiftShow22, R.assetsImagesGiftShow23, R.assetsImagesGiftShow24 ].map((imgName) => Image.asset(imgName)).toList(); item = ImgFrameAnimation(imgList: imgList); } else { var imgPath = 'assets/images/gift_anim_$giftId.gif'; item = Image.asset(imgPath); } return IgnorePointer( ignoring: true, child: Container( child: Material( color: Colors.black.withOpacity(0.7), child: Center(child: item)), alignment: Alignment.center, ), ); }); }); overlayState.insert(overlayEntry); //两秒后,移除Toast Future.delayed(Duration(seconds: 3)).then((value) { overlayEntry.remove(); }); } static showDashangEffect( BuildContext context, bool isMe, int amount, String itemName) { var overlayState = Overlay.of(context); OverlayEntry overlayEntry = OverlayEntry(builder: (context) { return Positioned( // left: isMe ? 10 : null, // right: !isMe ? 10 : null, bottom: 150, child: Container( width: Screen.width, alignment: Alignment .center, //isMe ? Alignment.centerLeft : Alignment.centerRight, child: Material( color: Colors.black.withOpacity(0), child: isMe ? fixedText( I18n.of(context) .send_gift .replaceFirst('/s1', amount.toString()) .replaceFirst('/s2', itemName), color: Colors.white) : fixedText( I18n.of(context) .receive_gift .replaceFirst('/s1', amount.toString()) .replaceFirst('/s2', itemName), color: Colors.white)), ), ); }); overlayState.insert(overlayEntry); //两秒后,移除Toast Future.delayed(Duration(seconds: 3)).then((value) { overlayEntry.remove(); }); } }