aslan-flutter/lib/chatvibe_managers/gift_animation_manager.dart
2026-07-01 18:25:58 +08:00

67 lines
1.6 KiB
Dart

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<LGiftModel> gifts = Queue<LGiftModel>();
List<LGiftScrollingScreenAnimsBean> aninControllers = [];
//每个控件正在播放的动画
Map<int, LGiftModel?> 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<LGiftScrollingScreenAnimsBean> 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();
}
}