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