Hibok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

84 regels
2.8 KiB

  1. import 'package:chat/generated/i18n.dart';
  2. import 'package:chat/r.dart';
  3. import 'package:chat/utils/image_frame_animation.dart';
  4. import 'package:chat/utils/screen.dart';
  5. import 'package:flutter/material.dart';
  6. class AnimEffect {
  7. static showEffect(BuildContext context, int giftId) {
  8. var overlayState = Overlay.of(context);
  9. OverlayEntry overlayEntry = OverlayEntry(builder: (context) {
  10. return LayoutBuilder(builder: (context, constraints) {
  11. var item;
  12. if (giftId == 2) {
  13. var imgList = [
  14. R.assetsImagesGiftShow21,
  15. R.assetsImagesGiftShow22,
  16. R.assetsImagesGiftShow23,
  17. R.assetsImagesGiftShow24
  18. ].map<Widget>((imgName) => Image.asset(imgName)).toList();
  19. item = ImgFrameAnimation(imgList: imgList);
  20. } else {
  21. var imgPath = 'assets/images/gift_anim_$giftId.gif';
  22. item = Image.asset(imgPath);
  23. }
  24. return IgnorePointer(
  25. ignoring: true,
  26. child: Container(
  27. child: Material(
  28. color: Colors.black.withOpacity(0.7),
  29. child: Center(child: item)),
  30. alignment: Alignment.center,
  31. ),
  32. );
  33. });
  34. });
  35. overlayState.insert(overlayEntry);
  36. //两秒后,移除Toast
  37. Future.delayed(Duration(seconds: 3)).then((value) {
  38. overlayEntry.remove();
  39. });
  40. }
  41. static showDashangEffect(
  42. BuildContext context, bool isMe, int amount, String itemName) {
  43. var overlayState = Overlay.of(context);
  44. OverlayEntry overlayEntry = OverlayEntry(builder: (context) {
  45. return Positioned(
  46. // left: isMe ? 10 : null,
  47. // right: !isMe ? 10 : null,
  48. bottom: 150,
  49. child: Container(
  50. width: Screen.width,
  51. alignment: Alignment
  52. .center, //isMe ? Alignment.centerLeft : Alignment.centerRight,
  53. child: Material(
  54. color: Colors.black.withOpacity(0),
  55. child: isMe
  56. ? fixedText(
  57. I18n.of(context)
  58. .send_gift
  59. .replaceFirst('/s1', amount.toString())
  60. .replaceFirst('/s2', itemName),
  61. color: Colors.white)
  62. : fixedText(
  63. I18n.of(context)
  64. .receive_gift
  65. .replaceFirst('/s1', amount.toString())
  66. .replaceFirst('/s2', itemName),
  67. color: Colors.white)),
  68. ),
  69. );
  70. });
  71. overlayState.insert(overlayEntry);
  72. //两秒后,移除Toast
  73. Future.delayed(Duration(seconds: 3)).then((value) {
  74. overlayEntry.remove();
  75. });
  76. }
  77. }