-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rating.dart
110 lines (98 loc) · 2.56 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
// ignore: file_names
import 'package:flutter/material.dart';
class RatingBox extends StatefulWidget {
const RatingBox({Key? key}) : super(key: key);
@override
_RatingBoxState createState() => _RatingBoxState();
}
class _RatingBoxState extends State<RatingBox> {
int _rating = 0;
void _setRatingAsOne() {
setState(() {
_rating = 1;
});
}
void _setRatingAsTwo() {
setState(() {
_rating = 2;
});
}
void _setRatingAsThree() {
setState(() {
_rating = 3;
});
}
void _setRatingAsFour() {
setState(() {
_rating = 4;
});
}
void _setRatingAsFive() {
setState(() {
_rating = 5;
});
}
@override
Widget build(BuildContext context) {
double _size = 20;
// ignore: avoid_print
print("_rating");
return Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
padding: const EdgeInsets.all(0),
child: IconButton(
icon: (_rating >= 1 ? Icon(Icons.numbers, size: _size,) :
Icon(Icons.star_border, size: _size,)),
color: Colors.red[500],
onPressed: _setRatingAsOne,
iconSize: _size,
),
),
Container(
padding: const EdgeInsets.all(0),
child: IconButton(
icon: (_rating >= 2 ? Icon(Icons.numbers, size: _size,) :
Icon(Icons.star_border, size: _size,)),
color: Colors.red[500],
onPressed: _setRatingAsTwo,
iconSize: _size,
),
),
Container(
padding: const EdgeInsets.all(0),
child: IconButton(
icon: (_rating >= 3 ? Icon(Icons.numbers, size: _size,) :
Icon(Icons.star_border, size: _size,)),
color: Colors.red[500],
onPressed: _setRatingAsThree,
iconSize: _size,
),
),
Container(
padding: const EdgeInsets.all(0),
child: IconButton(
icon: (_rating >= 4 ? Icon(Icons.numbers, size: _size,) :
Icon(Icons.star_border, size: _size,)),
color: Colors.red[500],
onPressed: _setRatingAsFour,
iconSize: _size,
),
),
Container(
padding: const EdgeInsets.all(0),
child: IconButton(
icon: (_rating >= 5 ? Icon(Icons.numbers, size: _size,) :
Icon(Icons.star_border, size: _size,)),
color: Colors.red[500],
onPressed: _setRatingAsFive,
iconSize: _size,
),
),
],
);
}
}