Skip to content

Commit 431155b

Browse files
committed
working on rating bar with emoticons
1 parent a512610 commit 431155b

File tree

2 files changed

+70
-38
lines changed

2 files changed

+70
-38
lines changed

example/lib/main.dart

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ class _MyHomePageState extends State<MyHomePage>
138138
backgroundColor: Colors.teal,
139139
// centerTitle: true,
140140
// leading: GFIconButton(icon: Icon(Icons.directions_bus), onPressed: (){}),
141-
title:
142-
const Text('UI Kit'),
141+
title: const Text('UI Kit'),
143142
// GFSegmentTabs(
144143
// tabController: tabController,
145144
// initialIndex: 0,
@@ -215,26 +214,34 @@ class _MyHomePageState extends State<MyHomePage>
215214
mainAxisAlignment: MainAxisAlignment.center,
216215
crossAxisAlignment: CrossAxisAlignment.center,
217216
children: <Widget>[
218-
217+
GFRating(
218+
value: _rating,
219+
onChanged: (value) {
220+
setState(() {
221+
_rating = value;
222+
print('user selected $_rating');
223+
});
224+
},
225+
),
219226

220227
GFRating(
221228
value: _rating,
222229
// size: 50,
223-
// filledIcon: Icon(
224-
// Icons.done_outline,
225-
// size: 40,
226-
// color: Colors.teal,
227-
// ),
228-
// halfFilledIcon: Icon(
229-
// Icons.done_all,
230-
// size: 40,
231-
// color: Colors.teal.withOpacity(0.75),
232-
// ),
233-
// defaultIcon: Icon(
234-
// Icons.done,
235-
// size: 40,
236-
// color: Colors.teal.withOpacity(0.25),
237-
// ),
230+
filledIcon: Icon(
231+
Icons.done_outline,
232+
size: 40,
233+
color: Colors.teal,
234+
),
235+
halfFilledIcon: Icon(
236+
Icons.done_all,
237+
size: 40,
238+
color: Colors.teal.withOpacity(0.75),
239+
),
240+
defaultIcon: Icon(
241+
Icons.done,
242+
size: 40,
243+
color: Colors.teal.withOpacity(0.25),
244+
),
238245
// spacing: 8,
239246
// color: Colors.teal,
240247
// borderColor: Colors.tealAccent,
@@ -247,6 +254,31 @@ class _MyHomePageState extends State<MyHomePage>
247254
},
248255
),
249256

257+
GFRating(
258+
value: _rating,
259+
filledIcon: Icon(
260+
Icons.sentiment_very_satisfied,
261+
color: Colors.green,
262+
size: 50,
263+
),
264+
halfFilledIcon: Icon(
265+
Icons.sentiment_neutral,
266+
color: Colors.amber,
267+
size: 50,
268+
),
269+
defaultIcon: Icon(
270+
Icons.sentiment_very_dissatisfied,
271+
color: Colors.red,
272+
size: 50,
273+
),
274+
onChanged: (value) {
275+
setState(() {
276+
_rating = value;
277+
print('user selected $_rating');
278+
});
279+
},
280+
),
281+
250282
GFRating(
251283
value: _userRating,
252284
filledIcon: Image.asset(
@@ -271,7 +303,7 @@ class _MyHomePageState extends State<MyHomePage>
271303
color: Colors.teal,
272304
borderColor: Colors.tealAccent,
273305
controller: _ratingController,
274-
textForm: true,
306+
showTextForm: true,
275307
suffixIcon: GFButton(
276308
type: GFButtonType.transparent,
277309
onPressed: () {
@@ -298,22 +330,22 @@ class _MyHomePageState extends State<MyHomePage>
298330
// overlaySearchListHeight: 100.0,
299331
searchQueryBuilder: (query, list) => list
300332
.where((item) =>
301-
item.toLowerCase().contains(query.toLowerCase()))
333+
item.toLowerCase().contains(query.toLowerCase()))
302334
.toList(),
303335
overlaySearchListItemBuilder: (item) => Container(
304-
padding: const EdgeInsets.all(8),
305-
child: Text(
306-
item,
307-
style: const TextStyle(fontSize: 18),
308-
),
309-
),
336+
padding: const EdgeInsets.all(8),
337+
child: Text(
338+
item,
339+
style: const TextStyle(fontSize: 18),
340+
),
341+
),
310342
// noItemsFoundWidget: Container(
311343
// color: Colors.green,
312344
// child: Text("no items found..."),
313345
// ),
314346
onItemSelected: (item) {
315347
setState(() {
316-
print('ssssssss $item');
348+
print('selected item $item');
317349
});
318350
}),
319351

@@ -587,13 +619,13 @@ class _MyHomePageState extends State<MyHomePage>
587619
// )
588620
// ),
589621

590-
GFButton(
591-
type: GFButtonType.transparent,
592-
color: GFColor.warning,
593-
onPressed: (){},
594-
text: 'whatsapp',
595-
icon: Icon(Icons.directions_bike),
596-
),
622+
GFButton(
623+
type: GFButtonType.transparent,
624+
color: GFColor.warning,
625+
onPressed: () {},
626+
text: 'whatsapp',
627+
icon: Icon(Icons.directions_bike),
628+
),
597629
//
598630
// GFButton(
599631
// text: "linkedin",

lib/components/rating/gf_rating.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class GFRating extends StatefulWidget {
1616
this.filledIcon,
1717
this.halfFilledIcon,
1818
this.allowHalfRating = true,
19-
this.textForm = false,
19+
this.showTextForm = false,
2020
this.suffixIcon,
2121
this.controller,
2222
this.inputDecorations,
@@ -58,7 +58,7 @@ class GFRating extends StatefulWidget {
5858
final RatingChangeCallback onChanged;
5959

6060
/// if true, shows rating [TextFormField] with the rating bar, that allows the user input to show rating
61-
final bool textForm;
61+
final bool showTextForm;
6262

6363
/// defines the design and funtion of rating [TextFormField]'s suffix icon
6464
final Widget suffixIcon;
@@ -90,7 +90,7 @@ class _GFRatingState extends State<GFRating> {
9090
color: widget.borderColor ?? Theme.of(context).primaryColor,
9191
size: GFSizesClass.getGFSize(widget.size),
9292
);
93-
} else if (!widget.textForm
93+
} else if (!widget.showTextForm
9494
? index > widget.value - (widget.allowHalfRating ? 0.5 : 1.0) &&
9595
index < widget.value
9696
: index + 1 == widget.value + 0.5) {
@@ -137,7 +137,7 @@ class _GFRatingState extends State<GFRating> {
137137
}
138138

139139
@override
140-
Widget build(BuildContext context) => widget.textForm
140+
Widget build(BuildContext context) => widget.showTextForm
141141
? Column(children: <Widget>[
142142
Container(
143143
margin: widget.margin,

0 commit comments

Comments
 (0)