-
Notifications
You must be signed in to change notification settings - Fork 0
/
rating.dart
117 lines (108 loc) · 3.07 KB
/
rating.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import 'package:flutter/material.dart';
typedef void RatingChangeCallback(int rating);
class StarRating extends StatefulWidget {
final int starCount;
final int rating;
final RatingChangeCallback onRatingChanged;
final Color color;
final double iconSize;
const StarRating(
{Key key,
this.starCount = 5,
this.rating,
@required this.onRatingChanged,
@required this.color,
this.iconSize = 20.0})
: super(key: key);
@override
_StarRatingState createState() => _StarRatingState();
}
class _StarRatingState extends State<StarRating> {
Widget buildStar(BuildContext context, int index) {
Icon icon;
if (index >= widget.rating) {
icon = new Icon(
Icons.star_border,
// ignore: deprecated_member_use
color: Theme.of(context).buttonColor,
size: widget.iconSize,
);
} else if (index > widget.rating - 1 && index < widget.rating) {
icon = new Icon(
Icons.star_half,
color: Color(0xffffbb20),
size: widget.iconSize,
);
} else {
icon = new Icon(
Icons.star,
color: Color(0xffffbb20),
size: widget.iconSize,
);
}
return new InkResponse(
onTap:
// ignore: unnecessary_null_comparison
widget.onRatingChanged == null
? null
: () => widget.onRatingChanged(index + 1),
child: icon,
);
}
@override
Widget build(BuildContext context) {
return new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: new List.generate(
widget.starCount, (index) => buildStar(context, index)));
}
}
// class StarRating extends StatelessWidget {
// final int starCount;
// final int rating;
// final RatingChangeCallback onRatingChanged;
// final Color color;
// final double iconSize;
// StarRating(
// {this.starCount = 5,
// this.rating,
// @required this.onRatingChanged,
// @required this.color,
// this.iconSize = 20.0});
// Widget buildStar(BuildContext context, int index) {
// Icon icon;
// if (index >= rating) {
// icon = new Icon(
// Icons.star_border,
// // ignore: deprecated_member_use
// color: Theme.of(context).buttonColor,
// size: iconSize,
// );
// } else if (index > rating - 1 && index < rating) {
// icon = new Icon(
// Icons.star_half,
// color: Color(0xffffbb20),
// size: iconSize,
// );
// } else {
// icon = new Icon(
// Icons.star,
// color: Color(0xffffbb20),
// size: iconSize,
// );
// }
// return new InkResponse(
// onTap:
// // ignore: unnecessary_null_comparison
// onRatingChanged == null ? null : () => onRatingChanged(index + 1),
// child: icon,
// );
// }
// @override
// Widget build(BuildContext context) {
// return new Row(
// mainAxisAlignment: MainAxisAlignment.start,
// children:
// new List.generate(starCount, (index) => buildStar(context, index)));
// }
// }