Skip to content

Commit 9303326

Browse files
committed
rating field user options added
1 parent a1646a2 commit 9303326

1 file changed

Lines changed: 53 additions & 48 deletions

File tree

lib/components/rating/gf_rating.dart

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class GFRating extends StatefulWidget {
1818
this.textFormRating = false,
1919
this.suffixIcon,
2020
this.ratingController,
21+
this.inputDecorations,
22+
this.margin,
23+
this.padding,
2124
}) : assert(rating != null);
2225

2326
/// defines total number of rating items
@@ -59,40 +62,46 @@ class GFRating extends StatefulWidget {
5962

6063
final TextEditingController ratingController;
6164

65+
final InputDecoration inputDecorations;
66+
67+
final EdgeInsets margin;
68+
69+
final EdgeInsets padding;
70+
6271
@override
6372
_GFRatingState createState() => _GFRatingState();
6473
}
6574

6675
class _GFRatingState extends State<GFRating> {
67-
6876
Widget buildRatingBar(BuildContext context, int index) {
6977
Widget icon;
7078
if (index >= widget.rating) {
7179
icon = widget.defaultIcon != null
7280
? widget.defaultIcon
7381
: Icon(
74-
Icons.star_border,
75-
color: widget.borderColor ?? Theme.of(context).primaryColor,
76-
size: widget.itemSize,
77-
);
82+
Icons.star_border,
83+
color: widget.borderColor ?? Theme.of(context).primaryColor,
84+
size: widget.itemSize,
85+
);
7886
} else if (!widget.textFormRating
79-
? index > widget.rating - (widget.allowHalfRating ? 0.5 : 1.0) && index < widget.rating
87+
? index > widget.rating - (widget.allowHalfRating ? 0.5 : 1.0) &&
88+
index < widget.rating
8089
: index + 1 == widget.rating + 0.5) {
8190
icon = widget.halfFilledIcon != null
8291
? widget.halfFilledIcon
8392
: Icon(
84-
Icons.star_half,
85-
color: widget.color ?? Theme.of(context).primaryColor,
86-
size: widget.itemSize,
87-
);
93+
Icons.star_half,
94+
color: widget.color ?? Theme.of(context).primaryColor,
95+
size: widget.itemSize,
96+
);
8897
} else {
8998
icon = widget.filledIcon != null
9099
? widget.filledIcon
91100
: Icon(
92-
Icons.star,
93-
color: widget.color ?? Theme.of(context).primaryColor,
94-
size: widget.itemSize,
95-
);
101+
Icons.star,
102+
color: widget.color ?? Theme.of(context).primaryColor,
103+
size: widget.itemSize,
104+
);
96105
}
97106

98107
return GestureDetector(
@@ -120,48 +129,44 @@ class _GFRatingState extends State<GFRating> {
120129
);
121130
}
122131

123-
// Widget ratingBar(BuildContext context) => ;
124-
125-
126-
@override
127-
Widget build(BuildContext context) => widget.textFormRating ? Column(
128-
children: <Widget>[
129-
Container(
130-
margin: const EdgeInsets.symmetric(vertical: 16),
131-
padding: const EdgeInsets.symmetric(horizontal: 16),
132-
child: TextFormField(
133-
controller: widget.ratingController,
134-
keyboardType: TextInputType.number,
135-
decoration: InputDecoration(
136-
border: const OutlineInputBorder(),
137-
hintText: 'Enter rating',
138-
labelText: 'Enter rating',
139-
suffixIcon: widget.suffixIcon,
132+
@override
133+
Widget build(BuildContext context) => widget.textFormRating
134+
? Column(children: <Widget>[
135+
Container(
136+
margin: const EdgeInsets.symmetric(vertical: 16),
137+
padding: const EdgeInsets.symmetric(horizontal: 16),
138+
child: TextFormField(
139+
controller: widget.ratingController,
140+
keyboardType: TextInputType.number,
141+
decoration: InputDecoration(
142+
border: const OutlineInputBorder(),
143+
hintText: 'Enter rating',
144+
labelText: 'Enter rating',
145+
suffixIcon: widget.suffixIcon,
146+
),
140147
),
141148
),
142-
),
143-
Material(
149+
Material(
150+
color: Colors.transparent,
151+
child: Wrap(
152+
alignment: WrapAlignment.center,
153+
spacing: widget.spacing,
154+
children: List.generate(
155+
widget.itemCount,
156+
(index) => buildRatingBar(context, index),
157+
),
158+
),
159+
)
160+
])
161+
: Material(
144162
color: Colors.transparent,
145163
child: Wrap(
146164
alignment: WrapAlignment.center,
147165
spacing: widget.spacing,
148166
children: List.generate(
149167
widget.itemCount,
150-
(index) => buildRatingBar(context, index),
168+
(index) => buildRatingBar(context, index),
151169
),
152170
),
153-
)
154-
]
155-
) : Material(
156-
color: Colors.transparent,
157-
child: Wrap(
158-
alignment: WrapAlignment.center,
159-
spacing: widget.spacing,
160-
children: List.generate(
161-
widget.itemCount,
162-
(index) => buildRatingBar(context, index),
163-
),
164-
),
165-
);
171+
);
166172
}
167-

0 commit comments

Comments
 (0)