import 'dart:collection'; import 'package:flutter/cupertino.dart'; import 'package:aslan/chatvibe_ui/widgets/room/anim/l_gift_animal_view.dart'; class GiftAnimationManager extends ChangeNotifier { Queue gifts = Queue(); List aninControllers = []; //每个控件正在播放的动画 Map giftMap = {0: null, 1: null, 2: null, 3: null}; void addGift(LGiftModel giftModel) { gifts.add(giftModel); playNext(); } ///开始播放 playNext() { if (gifts.isEmpty) { return; } var playGift = gifts.first; for (var key in giftMap.keys) { var value = giftMap[key]; if (value == null) { giftMap[key] = playGift; gifts.removeFirst(); notifyListeners(); aninControllers[key].controller.forward(from: 0); break; } else { if (value.labelId == playGift.labelId) { playGift.giftCount = value.giftCount + playGift.giftCount; giftMap[key] = playGift; gifts.removeFirst(); notifyListeners(); aninControllers[key].controller.forward(from: 0.45); break; } } } } void bindController(List anins) { aninControllers = anins; } void disposeAnim() { gifts.clear(); giftMap[0] = null; giftMap[1] = null; giftMap[2] = null; giftMap[3] = null; for (var element in aninControllers) { element.controller.dispose(); } } void animCompleted(int index) { giftMap[index] = null; notifyListeners(); playNext(); } }