import 'dart:math'; import 'package:lottie/lottie.dart'; class LocationAnalyseUtil { static LottieDelegates convertKeywordDelegates(List list) { const int placeholderCount = 6; // 占位 keyPath 名称,例如 keyword1, keyword2, ..., keyword6 final List keyPaths = List.generate(placeholderCount, (index) => 'keyword${index + 1}'); final List finalTexts; if (list.length < placeholderCount) { // 不足 6 个,循环填充 finalTexts = List.generate(placeholderCount, (index) => list[index % list.length]); } else { // 超过 6 个,随机取 6 个不重复 final List shuffled = List.from(list)..shuffle(Random()); finalTexts = shuffled.take(placeholderCount).toList(); } // 构建 Lottie 的 ValueDelegate 列表 final List valueDelegates = List.generate(placeholderCount, (index) { return ValueDelegate.text( [keyPaths[index], keyPaths[index]], value: finalTexts[index], ); }); // 更新绑定 return LottieDelegates(values: valueDelegates); } }