在列表中显示模型的给定值的评级并动态绘制颜色

Displaying rating with given value from model in list and painting colors dynamically

提问人:kris 提问时间:7/24/2023 更新时间:7/24/2023 访问量:22

问:

帮助!!! 我需要帮助实现一个逻辑,根据我拥有的模型数据,将评级星涂成金色(满分五星)。没有用户交互,只有显示评级。 我想在我的小部件列表中输出评级。

我的模型类:-

class Trending {
  const Trending({
    required this.image,
    required this.title,
    required this.genre,
    required this.subtitle,
    required this.rating,
  });

  final String image;
  final String title;
  final Genre genre;
  final String subtitle;
  final int rating;
}

我的傻瓜数据:-

const trendingHome = <Trending>[
  Trending(
      image: 'assets/images/psimg.jpg',
      title: 'The Havoc Bringer',
      rating: 4,
      genre: Genre.action,
      subtitle:
          'In a small town where the youths have been manipulated by their rulers a courageous Man stands up for his people...'),
  Trending(
      image: 'assets/images/img0.jpg',
      title: 'Chainsaw Wreck',
      rating: 5,
      genre: Genre.rpg,
      subtitle: ''),
];
Flutter Dart 索引 逻辑 评级

评论


答:

0赞 kris 7/24/2023 #1

我使用 List.generate 来构建星星,然后使用带有 int 参数作为索引的 Widget 构建器来构建评级图标并有条件地动态呈现颜色。

评论

0赞 Community 7/28/2023
正如目前所写的那样,你的答案尚不清楚。请编辑以添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。您可以在帮助中心找到有关如何写出好答案的更多信息。