栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何正确创建评分星条?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何正确创建评分星条?

太多重复和填充!h

无论如何,这就是我要做的。简单,可重用。您可以在没有点击的情况下使用它(没有点击会禁用波纹效果)。也是半颗星。如果未指定颜色,则对填充的星星使用原色。

typedef void RatingChangeCallback(double rating);class StarRating extends StatelessWidget {  final int starCount;  final double rating;  final RatingChangeCallback onRatingChanged;  final Color color;  StarRating({this.starCount = 5, this.rating = .0, this.onRatingChanged, this.color});  Widget buildStar(BuildContext context, int index) {    Icon icon;    if (index >= rating) {      icon = new Icon(        Icons.star_border,        color: Theme.of(context).buttonColor,      );    }    else if (index > rating - 1 && index < rating) {      icon = new Icon(        Icons.star_half,        color: color ?? Theme.of(context).primaryColor,      );    } else {      icon = new Icon(        Icons.star,        color: color ?? Theme.of(context).primaryColor,      );    }    return new InkResponse(      onTap: onRatingChanged == null ? null : () => onRatingChanged(index + 1.0),      child: icon,    );  }  @override  Widget build(BuildContext context) {    return new Row(children: new List.generate(starCount, (index) => buildStar(context, index)));  }}

You can then use it like this :

class Test extends StatefulWidget {  @override  _TestState createState() => new _TestState();}class _TestState extends State<Test> {  double rating = 3.5;  @override  Widget build(BuildContext context) {    return new StarRating(      rating: rating,      onRatingChanged: (rating) => setState(() => this.rating = rating),    );  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/391259.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号